小编典典

使用查询将数据插入到临时表中

sql

我有一个输出当前数据的现有查询,我想将其插入到Temp表中,但是这样做有一些问题。有人会对如何执行此操作有一些见解吗?

这是一个例子

SELECT *
FROM  (SELECT Received,
              Total,
              Answer,
              ( CASE
                  WHEN application LIKE '%STUFF%' THEN 'MORESTUFF'
                END ) AS application
       FROM   FirstTable
       WHERE  Recieved = 1
              AND application = 'MORESTUFF'
       GROUP  BY CASE
                   WHEN application LIKE '%STUFF%' THEN 'MORESTUFF'
                 END) data
WHERE  application LIKE isNull('%MORESTUFF%', '%')

这似乎当前以我需要的方式输出我的数据,但我想将其传递到临时表中。我的问题是我对SQL查询还很陌生,还没有找到一种方法来做到这一点。或者,即使有可能。如果不可能,是否有更好的方法将我要查找的数据获取WHERE application LIKE isNull('%MORESTUFF%','%')到临时表中?


阅读 241

收藏
2021-05-05

共1个答案

小编典典

SELECT *
INTO #Temp
FROM

  (SELECT
     Received,
     Total,
     Answer,
     (CASE WHEN application LIKE '%STUFF%' THEN 'MORESTUFF' END) AS application
   FROM
     FirstTable
   WHERE
     Recieved = 1 AND
     application = 'MORESTUFF'
   GROUP BY
     CASE WHEN application LIKE '%STUFF%' THEN 'MORESTUFF' END) data
WHERE
  application LIKE
    isNull(
      '%MORESTUFF%',
      '%')
2021-05-05