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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e3e09f-4be8c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e3e09f-4be8c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?