小编典典

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

all

我有一个输出当前数据的现有查询,我想将它插入到临时表中,但是这样做时遇到了一些问题。有人会对如何做到这一点有一些见解吗?

这是一个例子

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%','%')放入临时表中?


阅读 120

收藏
2022-08-27

共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%',
      '%')
2022-08-27