Using bcp utility to export SQL queries to a text file

后端 未结 1 839
慢半拍i
慢半拍i 2020-12-16 04:17

I debug a stored procedure (SQL Server 2005) and I need to find out some values in a datatable.

The procedure is run by an event of the application and I watch just

相关标签:
1条回答
  • 2020-12-16 04:47

    bcp out exports tables.

    To export a query use queryout instead - you'll need to wrap your query in "double quotes"

    set @logtext = '"select name, type from master.dbo.spt_values where number=6"' 
    --set @logtext = 'master.dbo.spt_values' 
    SET @cmd = 'bcp ' + @logtext + ' queryout "c:\spt_values.dat" -U uId -P uPass -c' 
    EXEC master..XP_CMDSHELL @cmd  
    

    http://msdn.microsoft.com/en-us/library/ms162802.aspx

    0 讨论(0)
提交回复
热议问题