can i get result of EXEC sp_executeSQL as record set?

  • DECLARE @query nvarchar(MAX) ;

    set @query = 'SELECT * FROM Products' ;

    EXEC sp_executeSQL @query

    is this query return the record set as normal 'SELECT * FROM Products' query?

  • Yes it will.

    with respect to performance it may different. but result will be same

  • While it will, you won't be able to manipulate results in the client.

    To do that, you'd need to INSERT into a temporary table within the dynamic SQL. That table, defined in advance in the client, would then contain the results of the query in the temp table, which could then be used in the client.

    Obviously, you should not use SELECT * (use explicit column names).


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • thanks

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

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