sql server 2005 print to csv

Posted on 2010-01-04
Last Modified: 2012-05-08
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

Question by:rgb192
    LVL 75

    Accepted Solution

    -- run this by selecting the output option as a file (query->results to -> file )
    select shipfirstname, shiplastname , shipaddress1, shipaddress2
    from orders
    where orderid = 'x'
    LVL 1

    Expert Comment

    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 ","

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video discusses moving either the default database or any database to a new volume.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now