select @sql='select * from application.dbo.'+@TableName1+''+char(13)+char(10)+'except'+char(13)+char(10)+'select * from '+'application_check'+'.dbo.'+@TableName1+''
exec sp_executesql @sql
select @script='bcp sp_executesql '+@sql+'queryout "D:\SNB\Test\datacheck.txt" -T -c -t "|"'
EXEC master..xp_cmdshell @script
错误:尝试将输出导出到文件时,复制方向必须为“in”,“out”或“format”
答案 0 :(得分:2)
一些修复:
"Sql Query"
select @sql='select * from application.dbo.'+ QUOTENAME(@TableName1)
+' except select * from application_check.dbo.'+ QUOTENAME(@TableName1)
SET @script='bcp "'+@sql+'" queryout "D:\SNB\Test\datacheck.txt" -T -c -t "|"'
EXEC master..xp_cmdshell @script
答案 1 :(得分:0)
select @sql='select * from application.dbo.'+@TableName1+''+char(13)+char(10)+'except'+char(13)+char(10)+'select * from '+'application_check'+'.dbo.'+@TableName1+''
-- exec sp_executesql @sql
select @script='bcp "'+@sql+'" queryout "D:\SNB\Test\datacheck.txt" -T -c -t "|"'
EXEC master..xp_cmdshell @script
您无需使用sp_executesql
。您可以使用查询本身。