当我尝试运行此程序时,它只是给了我BCP可用的开关。这是我第一次使用BCP。我正在尝试编写存储过程以将一天的数据导出为CSV。
declare @startdate as datetime = '2017-01-24'
declare @enddate as datetime = dateadd(day,1,@startdate)
declare @sql varchar(8000)
set @sql =
'bcp "select * from tblBOJEOJ
where system = ''MKEV03''
and [date] between ''' + cast(@startdate as nvarchar(11)) + ''' and ''' + cast(@enddate as nvarchar(11)) + ''' "
queryout D:\Temp\Galaxy\BOJEOJ_.csv
-c -t, -T -S ' + @@SERVERNAME
print @sql
exec master..xp_cmdshell @sql
的内容
由于
答案 0 :(得分:1)
BCP
很奇怪。将declare @sql varchar(8000)
set @sql =
'bcp "select * from tblBOJEOJ where system = ''MKEV03'' and [date] between ''' + cast(@startdate as nvarchar(11)) + ''' and ''' + cast(@enddate as nvarchar(11)) + ''' " queryout D:\Temp\Galaxy\BOJEOJ_.csv -c -t, -T -S ' + @@SERVERNAME
print @sql
exec master..xp_cmdshell @sql
命令保持在单行
{{1}}