我无法弄清楚存储过程出了什么问题。
CREATE PROCEDURE duplicatecheck2
@QmemberID INT,
@InputDate DATE
AS
INSERT INTO tbl_availableMembers
SELECT memberId
FROM tbl_attendancesheet
WHERE MemberId = @QmemberId
AND [date] = @InputDate
AND [clockin] IS NOT NULL
AND [clockout] IS NULL
UNION
INSERT INTO tbl_availableMembers
SELECT memberId
FROM tbl_attendancemembers
WHERE memberId NOT IN (SELECT memberId
FROM tbl_attendanceSheet)
WHERE date = @InputDate)
我得到这些错误:
第156条消息,第15级,状态1,过程重复检查2,第14行
关键字“插入”附近的语法不正确。第156条消息,第15级,状态1,过程重复检查2,第18行
关键字“ WHERE”附近的语法不正确。
我在其中工作过的其他存储过程:
CREATE PROCEDURE duplicateCheck
@inputdate DATE
AS
BEGIN
DELETE FROM tbl_availableMembers
INSERT INTO tbl_availableMembers
SELECT memberId
FROM tbl_attendancemembers
WHERE memberId NOT IN (SELECT memberId FROM tbl_attendanceSheet)
UNION
SELECT memberId
FROM tbl_attendancemembers
WHERE memberId IN (SELECT memberId
FROM tbl_attendanceSheet
GROUP BY memberId, date
HAVING COUNT(*) <= 1 AND date = @inputdate)
END
答案 0 :(得分:1)
摆脱“联盟”。该存储过程只能运行两个insert语句。
Noel
答案 1 :(得分:0)
您不能将UNION应用于两个INSERT语句(如您的第一个代码段中)-但可以将其应用于两个SELECT语句(如您的第二个代码示例中) 通过@marc_s