陈述时的情况

时间:2017-06-23 15:04:03

标签: sql

我是SQL的新手(约4个月)并尝试替换我无法访问底层SQL代码的过时报告。在尝试替换它时,我已将以下内容作为测试,但在关键字' AS'附近出现错误'语法错误。

当我删除两个AS语句时,我在关键字' FROM'附近出现错误'语法错误。我忽略了一些非常基本的东西吗?我还在学习CASE语句,但我相信我在这里正确使用Case Searched格式来允许布尔WHEN语句。提前谢谢。

DECLARE @DATE AS DATETIME
SET @Date=GETDATE()

SELECT
j.team_name
, r.contractname
, r.contracttype
, r.requisitiontype
, r.reason
, r.hm
, j.city_name
, j.state_name
, j.positionid
, r.nci_job_title
, r.recruiter
, j.created_datetime
, DATEDIFF(d,j.created_datetime,@Date
, r.anticipatedstartdate
, DATEDIFF(d,@Date,r.anticipatedstartdate)
, CASE 
    WHEN c.hiring_status_desc = 'Applicant Submittal' AND DATEDIFF(d,@Date,c.DateCreated) < 7 THEN COUNT(c.DateCreated) 
    ELSE 0 
END AS 'SubmittalsThisWeek'
, CASE 
    WHEN c.hiring_status_desc = 'Applicant Submittal' THEN COUNT(c.DateCreated)
    ELSE 0 
END AS 'TotalSubmittals'

--Add more cases

FROM tblrequisition r

JOIN tbljobs j 
    ON r.positionid = j.positionid

JOIN tbl candidateinterviewstat c 
    ON r.requisition_id = c.requisition_id

WHERE r.[requsition status] = 'Open'
AND r.positionid > 1000000

GROUP BY
j.team_name
, r.contractname
, r.contracttype
, r.requisitiontype
, r.reason
, r.hm
, j.city_name
, j.state_name
, j.positionid
, r.nci_job_title
, r.recruiter
, j.created_datetime
, DATEDIFF(d,j.created_datetime,@Date)
, r.anticipatedstartdate
, DATEDIFF(d,@Date,r.anticipatedstartdate)

0 个答案:

没有答案