我正在尝试使用union all收集的三组数据来运行insert语句。
如果我运行select语句它们正常工作,但如果我运行insert语句,我会收到以下错误:
Msg 137, Level 15, State 2, Line 6
Must declare the scalar variable "@_EventSessionID".
Msg 137, Level 15, State 2, Line 23
Must declare the scalar variable "@_EventSessionID".
Msg 137, Level 15, State 2, Line 40
Must declare the scalar variable "@_EventSessionID".
**Msg 156, Level 15, State 1, Line 52
Incorrect syntax near the keyword 'AND'.**
声明标量变量是一个逻辑错误,但这些错误将由我运行它的应用程序提供。我无法弄清楚的是以粗体描述的消息。
我正在尝试运行的查询的最后一部分(包括插入部分)如下。希望有人能帮助我!
INSERT INTO _conn_tb_request
(_mode,
type,
_eventsessionid,
_task,
employeeid,
freeintfield_01,
freetextfield_01,
description,
startdate,
enddate,
freeguidfield_01,
freeguidfield_02,
freetextfield_03)
SELECT 0,
96,
@_EventSessionID,
@_EventDescription,
res_id,
fullname,
Datepart(yyyy, Getdate()),
'RGA',
'RGA gesprek '
+ Cast(Datepart(yyyy, Getdate()) AS VARCHAR)
+ ' - ' + fullname,
Dateadd(yy, Datediff(yy, 0, Getdate()), 0),
Dateadd(mm, 2, Dateadd(yy, Datediff(yy, 0, Getdate()), 0)),
'3C11435F-598B-4164-8CFD-9A943ED30262',
ab.id,
ab.freetextfield_02
FROM humres hu (nolock)
LEFT JOIN absences ab (nolock)
ON hu.res_id = ab.empid
AND ab.type = 96
AND ab.freetextfield_01 = 'RGA'
AND ab.freeintfield_01 = Datepart(yyyy, Dateadd(yy, -1, (
Getdate() ))
)
WHERE ldatindienst < Dateadd(yy, -1, ( Dateadd(dd, 1, ( Dateadd(qq,
Datediff(qq, 0,
Getdate()),
-1) )
) ))
AND emp_type IN ( 'E' )
AND emp_stat = 'A'
AND hu.res_id NOT IN (SELECT empid
FROM absences (nolock)
WHERE type = 96
AND freetextfield_01 = 'RGA'
AND freeintfield_01 = Datepart(yyyy, Getdate
()))
AND Dateadd(yy, Datediff(yy, 0, Getdate()), 0) < Getdate()
答案 0 :(得分:0)
请参阅第24行演员(Datepart(yyyy,Getdate())AS VARCHAR)。 括号问题。