September 15, 2009 at 7:07 am
Hi All,
I need to save the results of any Query to a delimited .txt (Any Delimiter)
however i need it to be saved from within a SQL Proc, which will be called every night
in a job.
Any Help Please...
September 15, 2009 at 7:17 am
Hi,
You can use bcp with xp_cmdshell or openrowset. Please refer to the following links. I recommend you to use open rowset. Please refer the following links.
bcp with xp_cmdshell
http://www.mssqltips.com/tip.asp?tip=1633
openrowset
http://www.mssqltips.com/tip.asp?tip=1202
[font="Verdana"]Thanks
Chandra Mohan[/font]
September 15, 2009 at 7:20 am
both bcp and the more robust sqlcmd have the ability to be fed a query and output the results to a file;
that is your best choices, unless you write/find a CLR to do it for you instead.
Lowell
September 15, 2009 at 8:08 am
Thanks Guys,
Im looking into it now...
September 15, 2009 at 8:11 am
If you are using a job to send the results to a .txt file, the one alternative way would be to create a SSIS package to extract the data and create the file and then schedule this package as run as your nightly job.,
September 15, 2009 at 11:08 am
Hi,
i faced a similar problem and i created a stored procedure that uses bcp, fmt format file and xp_cmdshell..
The code follow this:
select @cmd = 'bcp "SELECT column from table" queryout ' D:\exported.txt -f D:\format.fmt - T
EXEC @rc = master..xp_cmdshell @cmd
IF @rc 0
BEGIN
PRINT 'cmd faillure!'
return 1
END
ELSE
BEGIN
Print 'cmd execution ok!'
return 0
END
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy