我想将标量变量的结果发送到文本文件中,
我的代码看起来像这样
DECLARE @test varchar(10)
SET @test='This is sample text'
EXEC master..xp_cmdshell'bcp ' + @test + ' queryout "D:\sample.txt" -S LocalHost -U
sa -P 123 -c -T -t'
但这显示了以下错误
output
usage: bcp {dbtable | query} {in | out | queryout | format} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n native type] [-c character type] [-w wide character type]
[-N keep non-text native] [-V file format version] [-q quoted identifier]
[-C code page specifier] [-t field terminator] [-r row terminator]
[-i inputfile] [-o outfile] [-a packetsize]
[-S server name] [-U username] [-P password]
[-T trusted connection] [-v version] [-R regional enable]
[-k keep null values] [-E keep identity values]
[-h "load hints"] [-x generate xml format file]
NULL
不知道如何在 bcp 命令中给出分配标量变量值的格式 请任何人帮助。
并以这种方式尝试过
Create table #sample
(
productid int
)
Insert into #sample(productid) values(1001098)
EXEC master..xp_cmdshell'bcp "select * from #sample" queryout "D:\sample.txt" -S
LocalHost -U sa -P 123 -c -T -t'
它给出了错误
#sample does not exist (in bcp command line)
任何人都可以解决这个问题。提前致谢。