exporting sql query resultset to cvs or xls

  • Hi All,

    I want to export data retrived using a complex query in csv or xls file format for sending to my clients.

    Is there a way of generating the same on sql server or it has to be done using a front end like asp or vb.

    Thanks in advance.

    Tushar Chheda

  • You can generate csv or xls from Sql Server DTS

    Lots of info and tutorials on sqldts.com

  • Thanks Ray

    but my problem is i do not want to use dts, i want to generate using sql stored procedure or query analyzer.

    Regards,

    Tushar Chheda

  • if you can do manually on Query Analyser, right click on results after executing query and save as csv file...

    if you want to do in automation you can use BCP or OSQL commands...


    bondada

  • 'Try this:

    'Here's your recordset:

    set rsp=objConnhc.Execute(sql)

    'Then write the recordset to your CSV file, here's example MyFile.CSV

    Open "MyFile.CSV" For Output as #1

    For Each F In rsp.Fields

    Head = Head & ", " & F.Name

    Next Head = Mid(Head,3) & vbCrLf

    Response.ContentType = "text/plain"

    Response.Write Head

    Response.Write rsp.GetString(,,", ",vbCrLf,"")

    close #1

    Response.end

    %>

    Good Luck.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply