April 22, 2008 at 3:31 pm
I am running a simple select statement and exporting the returned data to a text file. The xp_cmdshell and OSQL work fine with the exception that at the start of each line the is a blank space added. Has anyone seen this before? Here are the commands;
SET @SQLSelect = 'SET NOCOUNT ON SELECT RTRIM(CONVERT(VARCHAR(700), Import)) FROM TABLE WHERE RunID=' + LTRIM(STR(@RunID)) + ' ORDER BY InvoiceNum, LineItem'
SET @SAPExportFile = 'C:\TEMP\SAPImport_' + @Filedate + '.dat'
SET @cmd = 'osql -E -S SERVERNAME -d DBNAME -h-1 -w 1029 /Q"' + @SQLSelect + '" /o ' + @SAPExportFile
EXEC master.dbo.xp_cmdshell @cmd, NO_OUTPUT
April 25, 2008 at 4:39 am
Hi,
I'm not sure why OSQL does that, but as far as I know, it always has (?!?).
Could you not use BCP to get the same resultset to a file without the extraneous space?
There's also an article about OSQL and it's leading spaces here:
http://zxat.net/whoami/pgOSQL.aspx
HTH,
April 25, 2008 at 6:39 am
Thanks for the information and the link. Since we are moving to SQL2005 next week we are going to wait and use SQLCMD. Another reason to move off 2000.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply