• rayh 98086 (12/3/2013)


    Hi,

    I would like to get the results of three different queries and put them all into one temp table. I am trying as follows but does not seem to be working. Is there a better way to do this?

    INSERT INTO #Temp

    EXECUTE sp_executesql @SQL

    EXECUTE sp_executesql @SQL2

    EXECUTE sp_executesql @SQL3

    You have 3 statements going on there. The first is an insert exec followed by two more execs.

    In order for this to work you will need to specify insert for each statement.

    INSERT INTO #Temp

    EXECUTE sp_executesql @SQL

    INSERT INTO #Temp

    EXECUTE sp_executesql @SQL2

    INSERT INTO #Temp

    EXECUTE sp_executesql @SQL3

    Please be careful about sql injection. Your original code was wide open and this doesn't have any parameters so I assume it must still be vulnerable. I urge you to do yourself and your company a favor and read about sql injection.

    _______________________________________________________________

    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/