Saving my MS SQL Query results in a spread sheet or CSV file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alia Khan
    New Member
    • Jan 2007
    • 1

    Saving my MS SQL Query results in a spread sheet or CSV file

    Hi
    I am creating a dts in which I want to write my query results in a spread sheet
    I am using this syntax

    select Super_REgion, sum(num_of_offe rs) Contracts,
    sum(num_of_acnt s) Accounts
    from #ak1
    group by Super_Region
    into OUT File '\\nas-msw-04\c07874\My Documents\Month lyMetricsData/MonthlyEcims Data Prep'

    but it doesn't work.
    Alia
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    Try this instead:

    [PHP]DECLARE @FileName varchar(50),
    @bcpCommand varchar(2000)

    select @FileName = '\\nas-msw-04\c07874\My Documents\Month lyMetricsData/MonthlyEcims Data Prep'

    SET @bcpCommand = 'bcp "select Super_REgion, sum(num_of_offe rs) Contracts,
    sum(num_of_acnt s) Accounts
    from ##ak1
    group by Super_Region" queryout "'

    SET @bcpCommand = @bcpCommand + @FileName + '" -U UID -P PWD -c'

    EXEC master..xp_cmds hell @bcpCommand[/PHP]


    It should be ##ak1 not #ak1 in this case.

    Comment

    Working...