SQL查询语法错误

时间:2017-08-21 19:06:00

标签: sql sql-server syntax-error

我无法弄清楚为什么我会收到此错误。

我一直在关键字' FROM'附近收到不正确的语法。错误。

USE [DWH]
GO

IF OBJECT_ID('tempdb..#temp') IS NOT NULL                   
         DROP TABLE #temp     
create table #temp ([month] date, amt NUMERIC(36,2))

declare @date date = '1/1/16'

while @date <= '8/1/2017' BEGIN

IF OBJECT_ID('tempdb..#Members') IS NOT NULL                      
            DROP TABLE #Members     

select distinct MT1.MEMBER_ID
into #members                                                                                    
from DWH.[Dimensions].[D_MEMBER_T1] MT1
join DWH.[Dimensions].[D_MEMBER_T2] MT2 ON MT1.MEMBER_T1_SKEY = MT2.MEMBER_T1_SKEY
JOIN DWH.[Dimensions].[D_PROVIDER_T1] PT1 ON MT2.[PCP_PROVIDER_T1_SKEY] = PT1.PROVIDER_T1_SKEY

WHERE @date BETWEEN MT2.EFFECTIVE_START_DATE AND MT2.EFFECTIVE_END_DATE
AND MT2.[MEM_ELIGIBILITY_STATUS_FLAG] = 'Y'
AND PT1.TAX_ID IN (                   '610654587',
                              '205494939',
                              '205497203',
                              '610444707',
                              '610461940')

insert into #temp

SELECT @DATE, (CAST(ROUND(SUM([PAID_AMT])*1.00,2) AS NUMERIC (36,2))

  FROM DWH.[Dimensions].[D_CLAIM_LINE_PHARMACY_DETAIL_T1]

  WHERE DATEPART (YYYY,FILL_DATE) = DATEPART (YYYY,@DATE)
  AND DATEPART (MM,FILL_DATE) = DATEPART (MM,@DATE)

  SET @DATE = DATEADD (MM,1,@DATE)
  END

SELECT * FROM #TEMP
GO

1 个答案:

答案 0 :(得分:0)

此代码具有不平衡的括号:

SELECT @DATE, (CAST(ROUND(SUM([PAID_AMT])*1.00,2) AS NUMERIC (36,2))
--------------^
FROM DWH.[Dimensions].[D_CLAIM_LINE_PHARMACY_DETAIL_T1]

应该是:

SELECT @DATE, CAST(ROUND(SUM([PAID_AMT])*1.00, 2) AS NUMERIC (36, 2))
FROM DWH.[Dimensions].[D_CLAIM_LINE_PHARMACY_DETAIL_T1]

FROM位于括号中,产生错误。