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 2005 Forums
 Transact-SQL (2005)
 Query result in file

Author  Topic 

pyromelana
Starting Member

23 Posts

Posted - 2009-03-17 : 12:05:40
I would like to write the result of my query into a result.txt- file on the server
How can I do this? Do I have to write a cmdshell (or whatever) or are there some sql-statements that are able to write the result into a txt?

pootle_flump

1064 Posts

Posted - 2009-03-17 : 12:13:57
Can you use xp_cmdshell? Have you used BCP?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-17 : 13:20:46
if you're asking about editor in sql mgmnt studio, you've an option results as file where on executing query it will ask for saving to file the results.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-17 : 13:21:34
another way is to use bcp with query out option

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/bcp-export-data-to-text-file.aspx
Go to Top of Page

pyromelana
Starting Member

23 Posts

Posted - 2009-03-18 : 06:55:26
quote:
Originally posted by visakh16

if you're asking about editor in sql mgmnt studio, you've an option results as file where on executing query it will ask for saving to file the results.



Sorry, did not get it... Do you tell me that the SQL Server Management Studio has this possibility? Ok, not clear for me. Never mind, how does it work?
Go to Top of Page

matty
Posting Yak Master

161 Posts

Posted - 2009-03-18 : 07:03:01
In SQL Server Management Studio ,Choose from Query->Results To ->Results To File
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-03-18 : 07:04:21
declare @BCP_MissingLinks varchar(8000)

select @BCP_MissingLinks = 'bcp '+'"select Linkname from project.dbo.BCPLinkname"'+' queryout e:\Reports\MissingLinks.csv -c -t, -S172.16.3.226 -Usa -Pxxxxxxx'


exec master..xp_cmdshell @BCP_MissingLinks

Regards

Senthil.C
----------------------------------------------------------------------------
Server: Msg 3902, Level 16, State 1, Line 1
The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-18 : 07:45:25
quote:
Originally posted by visakh16

if you're asking about editor in sql mgmnt studio, you've an option results as file where on executing query it will ask for saving to file the results.



this wouldn't save result on the server. it'll save it on client machine. O/P wants it on server.
Go to Top of Page

pyromelana
Starting Member

23 Posts

Posted - 2009-03-18 : 08:32:17
quote:
Originally posted by matty

In SQL Server Management Studio ,Choose from Query->Results To ->Results To File




LOL.. joking or what? In the final version there is noone who can click... that should later work automatically...
Go to Top of Page
   

- Advertisement -