Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

export table contents to csv

$
0
0

Hi there,

Straight to the point I have the following code in a stored procedure:

    DECLARE @FilePath VARCHAR(500)
	DECLARE @SQL VARCHAR(500)

	SET @SQL='SELECT * FROM blah blah;'
		
	SET @FilePath='C:\blah\blah.csv'
	
	SET @SQL='SQLCMD -E -Q "SET NOCOUNT ON; '+@SQL+'" -o "'+@FilePath+'" -h-1 -s "," -W'
	-- -h-1 for no header
	-- if remove -h-1 then 1 header
	--  -h1 then after every row there is header and so on
	EXEC master..xp_cmdshell @SQL
	END

It runs okay and produces no errors, gives the result output NULL and Return Value 0. Its as though its worked but I get nothing on the network? Any one any idea's?

:)


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>