Click here to Skip to main content
15,991,072 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Iam executing one query but giving error statment..
SQL
declare @cmd varchar(1000)
select @cmd = 'osql -U -P -S -Q"select * from master..sysobjects" -o"c:\osqloutput.txt" -w500'
exec master..xp_cmdshell @cmd


error is like this

output
Error: Invalid usage of parameter -U.
NULL

-----------------------------------

one mor iam trying
master..xp_cmdshell 'bcp sava..select * from tbl_fs_mst out D:\file.bcp -S -U -P -c '

error is like this

CSS
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
Posted
Updated 18-Jun-15 21:39pm
v3
Comments
RossMW 19-Jun-15 3:44am    
Have you tried running the command in cmd window to test if it the xp_cmdshell or the command you are trying to run

1 solution

You haven't supplied the user login after the -U (no space).

You will also get a problem with the -P as you haven't supplied the password (also no space).

NB both are case-sensitive.

You will then get an issue with the -S as you haven't supplied the server name.

Note that osql is to be removed from SQL Server at some time in the future - sqlcmd[^] is now the recommended command-line utility
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900