View Single Post

   
  #3 (permalink)  
Old 02-28-2008, 07:50 PM
Bob
 
Posts: n/a
Default Re: OSQL Output File Garbage

Dan,

Thanks for the answers. I completely missed the -n option in the BOL.

I also like your alternative. Someone I work with suggested using a
temporary table then just selecting what I want but your approach
seems even more sophicated. I'm out of the office today so haven't
had a chance to try either answer but will as soon as possible.

Thanks so much,
Bob

"Dan Guzman" <danguzman@nospam-earthlink.net> wrote in message news:<Rkftb.917$Rk5.180@newsread1.news.atl.earthli nk.net>...
> You can remove numbering with the '-n' OSQL parameter.
>
> However, you might consider using dynamic SQL to accomplish the task.
> Example below:
>
> SET NOCOUNT ON
> CREATE TABLE #TableRowCounts
> (
> TableName nvarchar(261) NOT NULL,
> TableRowCount bigint NOT NULL
> )
> DECLARE
> @TableName nvarchar(261),
> @SqlStatement nvarchar(500)
> DECLARE TableList CURSOR
> LOCAL FAST_FORWARD READ_ONLY FOR
> SELECT
> QUOTENAME(TABLE_SCHEMA) +
> '.' +
> QUOTENAME(TABLE_NAME) AS TableName
> FROM INFORMATION_SCHEMA.TABLES
> WHERE OBJECTPROPERTY(
> OBJECT_ID(
> QUOTENAME(TABLE_SCHEMA) +
> '.' +
> QUOTENAME(TABLE_NAME)),
> 'IsMSShipped') = 0
> OPEN TableList
> WHILE 1 = 1
> BEGIN
> FETCH NEXT FROM TableList INTO @TableName
> IF @@FETCH_STATUS = -1 BREAK
> SET @SqlStatement =
> N'INSERT INTO #TableRowCounts
> SELECT ''' + @TableName + N''', COUNT(*)
> FROM ' + @TableName + N' WITH (NOLOCK)'
> EXEC (@SqlStatement)
> END
> CLOSE TableList
> DEALLOCATE TableList
>
> SELECT *
> FROM #TableRowCounts
> WHERE TableRowCount > 0
> ORDER BY TableName
>
>
> --
> Hope this helps.
>
> Dan Guzman
> SQL Server MVP
>
> -----------------------
> SQL FAQ links (courtesy Neil Pike):
>
> http://www.ntfaq.com/Articles/Index....partmentID=800
> http://www.sqlserverfaq.com
> http://www.mssqlserver.com/faq
> -----------------------
>

Reply With Quote