スカラー変数の結果をテキスト ファイルに送信したいのですが、
私のコードは次のようになります
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)
誰でもこれを解決してください。前もって感謝します。