Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

char(13) not working as intended

Status
Not open for further replies.

bmacbmac

IS-IT--Management
Jan 26, 2006
392
US
Hi. I am trying to write a query where the results can be copied into a batch file. I need the two strings/commands to be on their own lines. I am trying this:
Copy specific file to c:\temp
then run c:\program files\export\export.exe
then copy the next file, etc...

Code:
select 'copy ' + filename + ' c:\temp\*.*' + char(13) + char(10) + ' "c:\program files\export\export.exe"'
from mytable

I am copying my query results to notepad, Microsoft Word, etc, but not getting a carriage return with char(13) + char(10). It actually just inserts two spaces so I get this:

copy 12345.tif c:\temp\*.* "c:\program files\export\export.exe"
copy 12346.tif c:\temp\*.* "c:\program files\export\export.exe"

instead of this:

copy 12345.tif c:\temp\*.*
"c:\program files\export\export.exe"
copy 12346.tif c:\temp\*.*
"c:\program files\export\export.exe"

I would love to actually make each string on it's own line in the results window so I can just save the file as I need. Not sure if this is even possible.

Any ideas?

Thanks!

Brian
 
SSMS removes CR LF in the grid. Try:
Code:
DECLARE @sql varchar(max)
SET @sql = ''
SELECT @sql = @sql + 'copy ' + filename + ' c:\temp\*.*' + char(13) + char(10) + ' "c:\program files\export\export.exe"' + char(13) + char(10)
from mytable 

print @sql
Then copy the result from Message tab

Borislav Borissov
VFP9 SP2, SQL Server
 
Alternatively, you can set the results to text. To do this...

Right click in the query window, click "results to", then click "results to text". You can also press CTRL T to change it to "results to text".

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top