Transfer SQL Data Results To Excel Sheet

  • -- (1) Number of calls received for each priority of call [for a specified date range]

    declare @startdate datetime,

    @finishdate datetime

    select RM.fldPriorityCode as 'Priority',

    count(RM.fldRequestID) as 'Calls'

    from tblRequestMaster RM

    where RM.fldPriorityCode between 1 and 5

    and RM.fldRequestDate between '01-01-2007' and '03-05-2007'

    and RM.fldRequestFlag like 'D'

    group by RM.fldPriorityCode

    union

    select

    'Total' as 'Priority',

    count(RM.fldRequestID) as 'Calls'

    from tblRequestMaster RM

    where RM.fldPriorityCode between 1 and 5

    and RM.fldRequestDate between '01-01-2007' and '03-05-2007'

    and RM.fldRequestFlag like 'D'

    order by RM.fldPriorityCode asc

    Results:

    PriorityCalls

    120

    22912

    3152

    4571

    54

    Total3659

    I would like to transfer these results to an excel sheet. For instance when the user opens up the excel worksheet and types in for a example a start date: 01-01-2007 and an end date: 03-05-2007 (into textboxes) then clicks a button say called 'Get stats' and then the results appear on the sheet.

    How can this be done?

    ------------------------------------------------
    http://floetichoney.spaces.live.com
    ------------------------------------------------

  • From the Excel Help file.

    You can import data to Excel from most data sources by pointing to Import External Data on the Data menu, clicking Import Data, and then choosing the data you want to import in the Select Data Source dialog box.

    The Data Connection Wizard, available when you click New Source in the Select Data Source dialog box, makes it possible to import data from external data connections not available from the Select Data Source dialog box. These sources may include OLE DB data sources (including OLAP cubes and exchange servers) and any data sources a system administrator supplies. You cannot filter or join data in the Data Connection Wizard.

    Regards,
    Matt

  • Another altenative could be that you uses macros in excel.

    1) Create a Data Table on the excel sheet

    2) Create a connection ( odbc ).  ( VBA )

    3 ) Event handeling is possible in Excel macros. Dynamically generate your query based on the parameters and pass the query to the DataTable.

    Caution: It can get complicated if you want to manager file permissions.

    Fahrenheit

     

  • you can also use a DTS package to create an excel output

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

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