June 6, 2006 at 9:36 am
On TSQL Command of;
set nocount on
select @@version
Getting the output as;
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Microsoft SQL Server 2000 - 8.00.2039 (Intel X86)
May 3 2005 23:18:38
Copyright (c) 1988-2003 Microsoft Corporation
Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 2)
How to remove the lines from the output?
June 6, 2006 at 9:40 am
how about this:
set nocount on
select @@version
select replace(replace(@@version,char(13),''),char(10),'')
results:
Microsoft SQL Server 2000 - 8.00.760 (Intel X86) Dec 17 2002 14:22:05 Copyright (c) 1988-2003 Microsoft Corporation Personal Edition on Windows NT 5.0 (Build 2195: Service Pack 4)
Lowell
June 6, 2006 at 9:47 am
On any select statement output i want to eliminate the header line as below
"---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- "
June 6, 2006 at 9:54 am
Hi,
Press Ctrl + D before execution of your Query
and then Run Your Query
Regards,
AMIT GUPTA
MCDBA
June 6, 2006 at 9:57 am
this is part of the query analyzer: QA automatically puts the column names and a lineof dashes to separate the data from column names.
you will not get dashes if you are querying ther data from an applicaiton; it's just a display issue with QA;
alternatively within QA click control+D and run the query to get results in grid mode. then when you copy/paste, you get just the cell(s) you selected.
Lowell
June 6, 2006 at 9:58 am
June 6, 2006 at 10:32 am
i'm sure you already read the help that is available for osql; as you identified, there is no way to remove the line dashes separator directly with osql ; you can supress the batch numbers(-n param) and the column headers(-h1), but not the line the column headers would occupy, nor the separator line with all the dashes;
what you can do:
you would have to send the results to a text file, and start reading the results at line #3, where the data begins, or insert the results into a variable and read all results after the 2nd instance of CrLf.
you'll need to do that, or get your query results a different way, whether it is from an ADODB.recordset, or from a .net datatable, or whatever; it really depends on your application.
example:
c:\test.qry file:
set nocount on
select @@version
command:
osql /U sa /P -n -h1 -w 8000 /i c:\test.qry /o c:\results.res
Lowell
June 6, 2006 at 5:31 pm
Nice job Lowell,
Small correction, though... the switch to turn off the header and the dotted line is -h-1 and not just -h1.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 6, 2006 at 7:41 pm
print @@version
Tim Wilkinson
"If it doesn't work in practice, you're using the wrong theory"
- Immanuel Kant
June 6, 2006 at 8:06 pm
Doh! The simplest answer is usually the best and the most elusive... that'll sure do it, Tim! Good thinkin'
--Jeff Moden
Change is inevitable... Change for the better is not.
June 7, 2006 at 9:41 am
June 7, 2006 at 5:23 pm
Sure... no problem...
OSQL -SwSRVR01 -E -Q"set nocount on select name from sysobjects" -n -h-1
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply