Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 how to save results to file programatically

Author  Topic 

rolandsantos
Starting Member

24 Posts

Posted - 2008-03-11 : 06:09:08
gurus, how can i save the results of a query to a text file programatically? (w/o choosing the Results to file option in Analyzer and not through osql/isql)

example, the query "select * from suppliers"
will give me a suppliers.txt in drive C:

thanks in advance

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-03-11 : 06:22:48
[code]exec xp_cmdshell 'bcp "select * from suppliers" queryout "c:\suppliers.txt" -S server -T'[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-11 : 06:24:00
And the file will be created on your SQL Server c: drive, not your local c: drive.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

rolandsantos
Starting Member

24 Posts

Posted - 2008-03-14 : 01:51:09
thanks a lot guys..
Go to Top of Page

rolandsantos
Starting Member

24 Posts

Posted - 2008-03-14 : 02:08:52
anyway, the command works fine. but the result is not quite in a very readable format.

the command:
bcp "select top 1 * from northwind.dbo.suppliers" queryout "c:\suppliers.txt" -n -T

will result:
  E x o t i c L i q u i d s C h a r l o t t e C o o p e r $ P u r c h a s i n g M a n a g e r  4 9 G i l b e r t S t . L o n d o n ÿÿ E C 1 4 S D  U K  ( 1 7 1 ) 5 5 5 - 2 2 2 2 ÿÿÿÿÿÿ

any suggestions? thanks in advance
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-03-14 : 02:57:05
you are using -n native type output. Use a format file instead.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

rolandsantos
Starting Member

24 Posts

Posted - 2008-03-14 : 05:09:34
thanks.. using -c instead of -n will return the desired results...
nice day...
Go to Top of Page

johnsql
Posting Yak Master

161 Posts

Posted - 2008-03-21 : 11:07:49
quote:
Originally posted by Peso

And the file will be created on your SQL Server c: drive, not your local c: drive.



E 12°55'05.25"
N 56°04'39.16"




If I'd like to copy data from remote MS SQL Server to my local C drive, how can I do that?

Thanks in advance.
Go to Top of Page
   

- Advertisement -