sql server 2005 print to csv

want to print this to csv
as three columns
select shipfirstname, shiplastname from orders where orderid = 'x'

select shipaddress1 from orders where orderid = 'x'

select shipaddress2 from orders where orderid = 'x'

Open in new window

LVL 1
rgb192Asked:
Who is Participating?
 
Aneesh RetnakaranConnect With a Mentor Database AdministratorCommented:
-- run this by selecting the output option as a file (query->results to -> file )
select shipfirstname, shiplastname , shipaddress1, shipaddress2
from orders
where orderid = 'x'
0
 
danielaaronwilliamsCommented:
You can save this in a batch file to run:

SET /P _OrderNumber=Enter Order Number:
sqlcmd -U <username> -P <password> -S <servername> -d <databasename> -q "select shipfirstname, shiplastname, shipaddress1, shipaddress2 from orders where orderid = '%_OderNumber%" -h -1 -W -s ","
0
All Courses

From novice to tech pro — start learning today.