I am trying to export data into into a text file using bcp utility? I could n't figure out what i am doing wrong here:-
Declare @Cmd nvarchar(1000)
Declare @Query nvarchar(1000)
Declare @Path nvarchar(500)
Declare @ServerName nvarchar(500)
Declare @UserName nvarchar(50)
Declare @Password nvarchar(50)
Declare @Delimiter char(1)
SET @Path = 'c:\abc.txt'
SET @ServerName = '10.10.10.10\instance1'
Set @UserName = 'sa'
Set @Password = '123456'
Set @Delimiter = '!'
SET @Query = 'SELECT [ID]
, NULL
,[NAME]
,[STREET1] + '' '' + [STREET2] as [Address]
,[CITY] + '' '' + [PROVINCE] + '' '' + [POSTAL] as City
,[PHONE]
,[FAX]
,''Title'' as [Title]
,[Country]
FROM [temp01]'
SET @Cmd = 'bcp "' + @Query + '" queryout "' + @Path +
'" -c -S' + @ServerName + ' -U' + @UserName + ' -P' +
@Password + ' -t' + @Delimiter + ''
EXEC master..xp_cmdshell @Cmd
It is not writing any data into the file. In result box i am getting this 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"] NULL [-h "load hints"] NULL
Please help.