question

ahmed avatar image
ahmed asked

2 problems in directing query results to a text file

Dear All,

I have created a script to direct some query results to a text file ,the script is something like :

                    
DECLARE @FileName varchar(50),                    
        @bcpCommand varchar(2000)                    
                    
SET @FileName = REPLACE('c:\authors_'+CONVERT(char(8),GETDATE(),1)+'.txt','/','-')                    
                    
SET @bcpCommand = 'bcp "select * from [open].dbo.devlab" queryout "'                    
SET @bcpCommand = @bcpCommand + @FileName + '" -U sa -P lzbull@! -c'                    
                    
EXEC master..xp_cmdshell @bcpCommand                    

I have faced two problems if having an idea about one of them at least please advise :

1- the query directed includes information with a diffrent language then english (hindi, arabic...etc) i have notice that all the information written not in english appears in the text file as rubbish characters with no meaning , althought there is no problem in creating a manual text document with those languages, so how can i modify my script so that it writes proper characters in the text file for diffrent langauges ?

2- My script runs and works only when sql server is deffind as sql authentication , but if it is windows authentication i always get the message of unvalid login , so how can i but the correct user name and password in my script incase of windows authentication?

Thanks

sql-server-2008bcpcode-page
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Kristen avatar image
Kristen answered
  1. Use -T (trusted connection) parameter instead of "-U sa -P lzbull@!"

I'm not sure about (1). Perhaps the -C (note capital letter) option with a suitable code page, or perhaps even -C RAW

P.S. If that is really your SA password you need to change it now as the whole world will know it too :(

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.