steven
asked on
BCP command
I am trying to query out using with the below code, with no luck can anyone help.
declare @outfile nvarchar(200),
@comrun nvarchar(400)
set @outfile = '\\eincutil1\fstaskman\rep ort\output files\sa\' + db_name() + 'ALLOpenOrder.csv'
set @comrun = 'bcp " select order_date,
item,
description,
qty_ordered,
qty_avail,
job,
opername,
P_M_T_code
from einc_testapp.dbo.ensopenco A queryout"' + @outfile + ' -c -t, -T -SEINCDATA'
exec master..xp_cmdshell @comrun
The results are :
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"]
NULL
declare @outfile nvarchar(200),
@comrun nvarchar(400)
set @outfile = '\\eincutil1\fstaskman\rep
set @comrun = 'bcp " select order_date,
item,
description,
qty_ordered,
qty_avail,
job,
opername,
P_M_T_code
from einc_testapp.dbo.ensopenco
exec master..xp_cmdshell @comrun
The results are :
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"]
NULL
ASKER
Same result.
ASKER
Looks like its the commas that are causing the issue..any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Doh, I didn't even think about this initially: could you try getting rid of the carriage returns like this:
set @comrun = N'bcp "select order_date, item, description, qty_ordered, qty_avail, job, opername, P_M_T_code from einc_testapp.dbo.ensopenco A" queryout ' + @outfile + N' -c -t, -T -SEINCDATA'
edit: what harish said!
set @comrun = N'bcp "select order_date, item, description, qty_ordered, qty_avail, job, opername, P_M_T_code from einc_testapp.dbo.ensopenco
edit: what harish said!
set @comrun = N'bcp "select order_date,
item,
description,
qty_ordered,
qty_avail,
job,
opername,
P_M_T_code
from einc_testapp.dbo.ensopenco
edit: added the N unicode prefix to the set statement to prevent the casting