SQL re-query

  • question:
    can dynamic SQL be queried again?
    for example, the following code:

     DECLARE @SQL NVARCHAR(MAX)
     
     SELECT  @SQL =gcb.B_ProcessSQL
     FROM G_CJTouchB AS gcb 
     WHERE gcb.B_TouchName="XXX"
     
     SELECT *
     FROM (EXEC sp_executesql @SQL) 

    of course, the above code is wrong, and there will be an error on the last line.

  • Code introduction:
    query the field of data obtained from the table, where is the SQL statement
    after obtaining this SQL statement, the result set obtained by execution contains the data I need and some data that I do not use
  • my goal:
    can I execute the query again on the result set obtained by the query?
  • if necessary:
    you can contact me at 409223171@qq.com
Sql
Jun.03,2021

Yes, but with a little modification

select  id
from (select * from admin) t

just give your first query a table name. What is implemented in Chestnut is to query the admin table, and then extract the id field from the result set.

Menu