New Query with Previous Query Result...how?

  • Although I have been working quite a bit with SQL Server and ASP over the past couple of years, I do not consider myself proficient or extremely savvy...but I am willing to research, listen and learn.

    - - - - - - - - - - - - - -

    This HR web application that I am "fixing up" has quite a few existing routines during which I need to a) retrieve a list of employees and their information and b) perform additional queries with that information to get more information elsewhere.

    Although I have tried to use multiple joins and "nested queries" as much as possible, it is not always "do-able" (for me) to get, for example, all employee IDs and evaluation dates AND use that information to retrieve additional data from other tables in the same query.

    In short, sometimes I simply need to get one set of employee information, perform some data manipulation and then use that information to conduct another query.

    However, there must be a more efficient approach than to query SQL Server for each employee's information, create a list of ASP variables and then conduct another SQL Server query with those variables as values...yes?

    So does anyone know of a basic example that shows how this can be done? Any hints would be greatly appreciated!

     

    In case this issue has already been addressed elsewhere, please forgive me my ignorance and simply point me to the right place.

    Thanks much,

    MC

     

  • Load your output from the initial query into a temporary table.

    Steve

  • Steve,

    Thanks for that reply.

    Actually, I have been doing that, but I am somewhat reluctant to mention that in public -- for fear that somebody might accuse me of taking up valuable resources (even though only temporarily).

    However, your comment makes me feel quite confident.

     

    Thanks much,

    MC

     

  • Another option is to use a Table Variable. This just creates a table in memory, a temporary table is "pysically" created in tempdb.

    I use both techniques.

    /rockmoose


    You must unlearn what You have learnt

  • Thank you for that hint.

    I'll have to check this out right away. If you happen to have an example handy or know of a web site where that might be demonstrated, I'd be much obliged.

    Nonetheless, thank you very much,

    MC

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

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