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
Error: Copy direction must be either 'in', 'out' or 'format' while trying to export output into a file
A couple of fixes:
"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
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
You need not use sp_executesql
. You can use the query itself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.