Link to home
Start Free TrialLog in
Avatar of africaoh
africaoh

asked on

osql question

Hey everyone,

Simple question here...
How do I specify my delimiter with osql command (-s) if I would like to create a "tab-delimited" text file?
I tried  -s "\t"  didnt seem to work.

Please let me know.
Avatar of leonstryker
leonstryker
Flag of United States of America image

How to write values to a Text file

To write a result of a SELECT query in a text file :-

master..xp_cmdshell 'osql -SMyServer -Umyuser -Pmypwd
-Q"select * from products" -dNorthwind  -w"1000" -oc:\MyText.txt'

If you are running it from the prompt take out master..xp_cmdshell ' , and the final '  parts.

Avatar of africaoh
africaoh

ASKER

I know that, I just need to specify the correct delimiter for my text file that is the  -s  argument, do you know what to set -s to in order to generate tab delimited text file ?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/coprompt/cp_osql_1wxl.asp

-s col_separator

Specifies the column-separator character, which is a blank space by default. To use characters that have special meaning to the operating system (for example, | ; & < >), enclose the character in double quotation marks (").

Based on this I would say:     -s "|"
-s |    => pipe delimited not tab delimited
Avatar of Lowfatspread
isn't a tab a char(9)?


 
The only other thing I can think of is try -s \t  <-- without the quotes
Allready did try that, not working... then I end up with  \  as my delimiter
Lowfatspread - Im not sure what your getting at ?
Try just -c  without a switch.  I think tab may be a default setting
Try this:
     osql [Other Parameters] -c "^P"

Enter the ^P by hitting CTRL+P when typing the command line.

Hope this helps,
Dex*
The deafult is a space.

"^P" that is only from command line, I need to do this from my sp.

Any other ideas guys ?
It seems to work if you build your command line dynamically to include the Tab char explicitly, and then execute it like this:

DECLARE @strCommand VARCHAR(1000)

SET @strCommand =  'osql -SMyServer -Umyuser -Pmypwd -Q"select * from products" -dNorthwind  -w"1000" -oc:\MyText.txt -s"' + CHAR(9) + '"'

EXEC master..xp_cmdshell @strCommand

Hope this helps,
Dex*
ASKER CERTIFIED SOLUTION
Avatar of Dexstar
Dexstar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Dexstar,

Your solution works fine, only one more question, when I import this tab-delimted textfile into excel, the fields have alot of blank spaces (equal to the total field lenght) appended to it, any way one can get rid of the trailing spaces?
africaoh,

I don't see a way to prevent osql from adding those trailing spaces.  So, I think the best solution is to strip them off in Excel, after you've imported.  This could be done with a simple macro that TRIMs each cell.  I don't know your proficiency level with Excel, so maybe you can handle that on your own.  If not, I'll try to help you.

Hope my suggestion helps,
Dex*
africaoh

If you are importing the results into Excel anyway, why not use comma as your deliminator and save the file as a "MyText.csv"  Excel will automatically parse the result for you.
africaoh

If you are importing the results into Excel anyway, why not use comma as your deliminator and save the file as a "MyText.csv"  Excel will automatically parse the result for you.
africaoh

If you are importing the results into Excel anyway, why not use comma as your deliminator and save the file as a "MyText.csv"  Excel will automatically parse the result for you.
africaoh,

If you are importing the results into Excel anyway, why not use comma as your deliminator and save the file as a "MyText.csv"  Excel will automatically parse the result for you.
africaoh,

If you are importing the results into Excel anyway, why not use comma as your deliminator and save the file as a "MyText.csv"  Excel will automatically parse the result for you.
africaoh,

If you are importing the results into Excel anyway, why not use comma as your deliminator and save the file as a "MyText.csv"  Excel will automatically parse the result for you.
sorry - every one for the multiple posts, something wrong with our servers
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for all the ideas guys, really appreciate all your efforts. Will assign the credits now and try and sort it out based on your thoughts. Ragards.
Hallo i'm new member in this mailing list and i need hellp u,

what must i do to prevent on the SQL server 2000 ?

My condition Server is,
==================================================================
SQL Server Enterprise Manager

A Coonection could not be established to ServerX

Reason: General network error, Check your network documentation.
CoonectionOpen (PreloginHandshake())..

Please verify SQL Server is running and check your SQL Server
registration properties (by right-cliking on the ServerX node) and
try again.
==================================================================

My condition on Client,
==================================================================
SQL server stopped and can't akses again for client

- For client ping to Server SQL server it's oke
- From server not responding for login on SQL server Ent. Manager --
> SQL server Group.
- show,the Test on ODBC diclient ,

Connection failed:
SQLState:'01000'
SQL Server Error: 10060
[Microsoft}[ODBC SQL Server Driver][DBNETLIB]ConnectionOpen
(PreLoginHandshake()).
Connection failed:
SQlState:'08001'
SQL Server Error: 11
[Microsoft}[ODBC SQL Server Driver][DBNETLIB]General Network error.
Check your network documentation.
====================================================================
- Sometimes 2 on hours.
- To become normal windows server,ussualy must be restart the Server.

PS : data server,SQL Server 2000 Standard dengan Windows Server 2000
Sp 4

Please Help Me

Regards
Hp

H4ri,

This question is closed.  If you want to ask a question please open a new one.