April 9, 2004 at 5:39 am
I have a stored procedure that I would like to export this query to a .txt file.
select x from #x1
Can anyone help me with the bcp syntax of this inside my SP?
Thanks
Phil
April 9, 2004 at 6:21 am
Please refer to
http://www.sqlservercentral.com/scripts/contributions/1127.asp
Thanks
Prasad Bhogadi
www.inforaise.com
April 9, 2004 at 6:08 pm
Prasad,
Thanks for your input. BUT I have been trying everything to get it to work with no success. It must be in the syntax.
Any and all help is greatly appreciated.
Thanks,
Phil
April 12, 2004 at 10:21 am
I think you need to add servername as a prameter to the bcp command. Something like:
'bcp "SELECT ' + @varFieldList + ' FROM ' + @varTableName + '" QUERYOUT "' + @varOutFile + '" -T -c -S'
where is the full name of your server
April 12, 2004 at 10:22 am
OOPS ...the parameter should be visible now...
I think you need to add servername as a prameter to the bcp command. Something like:
'bcp "SELECT ' + @varFieldList + ' FROM ' + @varTableName + '" QUERYOUT "' + @varOutFile + '" -T -c -S[servername]'
where [servername] is the full name of your server
April 13, 2004 at 7:31 am
If you are trying to output the contents of your temp table using BCP, you will not be able to unless you use a global temp table.
for example to output the first 10 products on Northwind database to a csv file via a global temp table
SELECT TOP 10 *
INTO ##test
FROM Northwind.dbo.Products
exec master..xp_cmdshell 'bcp "SELECT * FROM ##test" queryout C:\temp\outputfile.csv -c -t ","'
DROP TABLE ##test
make sure you DROP the global temp table afterwards as it will not be automatically deleted on connection close
Far away is close at hand in the images of elsewhere.
Anon.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply