July 18, 2011 at 10:43 am
Hi,
I am using the below code to create a text file from SQL server 2005.
DECLARE @vCmd VARCHAR(MAX)
DECLARE @vCLUEDATE VARCHAR(MAX)
DECLARE @vWorkfilename VARCHAR(MAX)
SET @vCLUEDATE = '000000001EFHRCF01FF 20110718205227VERI2011071820110718 2'
SET @vWorkfilename = 'F:\ClueUpload\CVGVER.20110718.0101.txt'
Select@vCmd = 'echo ' + @vCLUEDATE + '>' + @vWorkfilename
EXEC master..xp_cmdshell @vCmd
But it is creating the file without data, but it should create with one line of data.
Then i changed the @vCmd as below
Select@vCmd = 'echo ' + @vCLUEDATE + ' > ' + @vWorkfilename
then it is working. but it is adding one space to the end of line that is after 2 it is adding. but i don't want that space, so how can I do this.
Please help me on this...
Regards,
Sarath Babu Vellampalli
Kindest Regards,
Sarath Vellampalli
July 18, 2011 at 7:15 pm
Interesting problem. I you remove the space before the 2 or change it to another character, the space after the string in the file goes away with your first CMD. If you use the second CMD, it returns the string to the screen (sans the 2). If you add 1 mor character after the 2, you also don't get a space on the first CMD.
Not sure what to do to fix it.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 18, 2011 at 7:52 pm
I'm not sure you can use an alternate answer but if you replace the spaces with underscores, all the problems vanish.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 18, 2011 at 8:28 pm
This will do it provided you understand that it will end the line with a CRLF
DECLARE @vCmd VARCHAR(8000)
DECLARE @vCLUEDATE VARCHAR(MAX)
DECLARE @vWorkfilename VARCHAR(MAX)
SET @vCLUEDATE = '000000001EFHRCF01FF 20110718205227VERI2011071820110718 2'
SET @vWorkfilename = 'c:\test.txt'
Select @vCmd = 'SQLCMD -E -dtempdb -h-1 -Q"SET NOCOUNT ON; SELECT ' + QUOTENAME(@vCLUEDATE,'''') + ';" -o' + @vWorkfilename
EXEC master..xp_cmdshell @vCmd
--Jeff Moden
Change is inevitable... Change for the better is not.
July 19, 2011 at 3:32 am
Thanks Jeff, it is working for me.
Kindest Regards,
Sarath Vellampalli
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply