Usando BCP com Select e espaços dentro das aspas duplas
05/05/2011
0
Bom dia,
Pessoal, resolvi postar isso no Forum por que fazem três dias que tento resolver este problema e não consigo.
Uso o BCP dentro de um JOB para gerar um arquivo XML, de uma tabela de clientes, para posteriormente importar para outro sistema.
A questão é que não consigo fazer com que o select dentro do BCP aceite espaços entre as aspas duplas.
Sei que se usar o For Element na minha consulta não teria problema, porém preciso usar o Explicit, para conseguir montar o XML da forma
O comando segue abaixo.
exec master..xp_cmdshell'BCP "SELECT ''<CustomerTransaction><Customer CUSTOMERID="544293450001" FULLNAME="94AURIQUIMICA LTDA" SHORTNAME="T170"><CustomerAddress ADDRESSLINE1="" ADDRESSLINE2="" ADDRESSLINE3="" CITY="Joinville" CONTACTNAME="" COUNTRY="" EMAILADDRESS="" FAX="" MAILCODE="" STATE="" TELEPHONE="" WEBSITE_URL=""/></Customer></CustomerTransaction>''" queryout "C:\Temp\0000000000002CUSTOMER.XML" -w -T -t -S172.16.50.83'
Ele executa corretamente se for usado o replace para trocar o espaço por _.
O erro que o SQL retorna:
Copy direction must be either 'in', 'out' or 'format'.
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]
[-d database name]
NULL
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]
[-d database name]
NULL
Giovani Zomer
Curtir tópico
+ 0
Responder
Posts
05/05/2011
Giovani Zomer
Bom dia,
Pessoal, resolvi postar isso no Forum por que fazem três dias que tento resolver este problema e não consigo.
Uso o BCP dentro de um JOB para gerar um arquivo XML, de uma tabela de clientes, para posteriormente importar para outro sistema.
A questão é que não consigo fazer com que o select dentro do BCP aceite espaços entre as aspas duplas.
Sei que se usar o For Element na minha consulta não teria problema, porém preciso usar o Explicit para conseguir montar o XML da forma que preciso.
O comando segue abaixo.
exec master..xp_cmdshell'BCP "SELECT ''"94AURIQUIMICA LTDA" SHORTNAME="T170">''" queryout "C:\Temp\0000000000002CUSTOMER.XML" -w -T -t -S172.16.50.83'
Ele executa corretamente se for usado o replace para trocar o espaço por _.
O erro que o SQL retorna:
Copy direction must be either 'in', 'out' or 'format'.
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]
[-d database name]
NULL
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]
[-d database name]
NULL
Responder
Clique aqui para fazer login e interagir na Comunidade :)