extracting data from sql 2005 to csv using a query

Proposed Answer extracting data from sql 2005 to csv using a query

  • Friday, November 25, 2011 1:49 PM
     
     

    I would like to export a table selecting only certain fields using a query rather than using the export wizard – as once my query is written, I only have to hit run everytime, saving me time.

     

    I have written the script of the variables I want (see below). but need to know if there is anything I can add to the script to be able to create a csv table from it by just clicking run once. 

    select distinct [Customer Ref No]

    [Customer Ref No],

    [Customer Title],

    [Customer Forename],

    [Customer Surname],

    [Company],

    [Address 1],

    [Address 2],

    [Address 3],

    [City],

    [County],

    [Postcode]

    fromclient.dbo.Bookers_2011

All Replies

  • Sunday, November 27, 2011 4:49 AM
     
     Proposed Answer Has Code

    HI,

    Did you try this code:

    SQLCMD -S MyInstance -E -d dbname -i query_file.sql -o output_file.csv -s ,
    



    Regards, Ryan Lambatan
    Please "Mark as Answer" or "Vote as Helpful"