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!

It it possible to have query results with carriage returns? 1

Status
Not open for further replies.

bmacbmac

IS-IT--Management
Jan 26, 2006
392
US
Hi... I am trying to create a batch file out of some query results. I need a few standard lines above and below my query results texts.

For example, I need it to look like this:

@@echo off
echo.
echo.
if not exist file1.doc echo file1.doc does not exist
if not exist file2.doc echo file2.doc does not exist
if not exist file3.doc echo file3.doc does not exist
echo.
echo.
pause

The SQL part of my script looks like this:
Code:
select 'if not exist ' + col001 + ' echo ' + col001 + ' does not exist'

Any idea how I can get the echos and the pause on their own lines? I'm hoping to create a SQL statement my user can copy/paste into a new .bat file each day or have the SQL statement create the .bat file for them.

I tried just having the echo's and pause as a template in an existing file but they wouldn't paste my SQl stements in the right spot. Hoping I can just have it all created for them.

This is SQL 2000.

Thanks!
 
Sure, just hard code a carriage return line feed, like this:

Code:
select '@echo off' [!]+ Char(13) + Char(10)[/!]
       + 'if not exist ' + col001 + ' echo ' + col001 + ' does not exist' [!]+ Char(13) + Char(10)[/!]

If you run this query in SQL Server Management Studio, you will not see the carriage return/line feed unless to set results to text (instead of grid). To do this, right click the query window, click "Results To" -> Text.


-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"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