• sqldba_newbie (7/3/2012)


    Steve Jones - SSC Editor (7/3/2012)


    Why does the table have to be created on the fly? You know the output of the proc already, so create the temp table using that basis.

    If you say you want one routine for all procs, you're being lazy. Create routines for each proc that needs this.

    Thanks. I am not a developer. I am just trying to come up a solution based on the requirement. I am sure we should go and optimize our queries. This is for a report. You have a sproc to generate report, if you have to query the output of the sproc how would you do that? I would still like to know if the method which i stated is possible or not.

    This whole thing just sounds like a monster kludge in the making. I see no reason for the dynamic sql at all and creating a generic proc to return data into an "on the fly" type of temp table so you can query it sounds like the process needs a lot of help. Why does a report need to take the results of a proc and then only get some of the rows? Why not change the original proc to return the data that you need?

    To directly answer your question, no you can't do this like you presented.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/