关于bcp的求助
bcp 导出文件的功能 除了 queryout 把查询结果导出以外,可否有办法直接导出某个变量?
set @dccs = 'bcp "select dcxml from ajxt..t_sms where smsid = '+cast(@smsid as varchar(10))+'" queryout g:'+DateName(year,GetDate())+DateName(month,GetDate())+DateName(day,GetDate())+DateName(hour,GetDate())+DateName(minute,GetDate())+DateName(second,GetDate())+'.xml -c -q -S"." -U"sa" -P"tlgl123"'
EXEC master..xp_cmdshell @dccs
这样的语句在我公司建模平台执行时会卡住,现在我想把查询结果 放到变量里 做成字符串 然后在导出试试,各位大神,有解决办法吗。。
[解决办法]
这样就可以实现,不过有个笔误g:...是g:\
[解决办法]
try this,
set @dccs='bcp "select dcxml from ajxt..t_sms where smsid='+cast(@smsid as varchar(10))+'" queryout g:\'+DateName(year,GetDate())+DateName(month,GetDate())+DateName(day,GetDate())+DateName(hour,GetDate())+DateName(minute,GetDate())+DateName(second,GetDate())+'.xml -c -q -S "." -U "sa" -P "tlgl123" '
exec master..xp_cmdshell @dccs
set @dccs = 'bcp "select dcxml from ajxt..t_sms where smsid = '+cast(@smsid as varchar(10))+'" queryout g:\'+DateName(year,GetDate())+DateName(month,GetDate())+DateName(day,GetDate())+DateName(hour,GetDate())+DateName(minute,GetDate())+DateName(second,GetDate())+'.xml -c -q -S"." -U"sa" -P"tlgl123"'