我正在尝试做的是,如果用户A打卡在2019/04/29,用户A将无法在该日期打卡,直到明天或后天。
因此,基本上这条SQL语句是有效的,但它不会向用户A显示任何错误,它将插入双倍记录。
IF EXISTS(select createddate from clockin where username = @Username and eventname = @b
group by createddate
HAVING COUNT(createddate) = 2
)这也不起作用,它不允许插入任何其他日期,因为29/04存在,它不允许30/04进入。HAVING COUNT(createddate) = 1
我想显示一个错误,如果用户尝试在2019/04/29打卡两次,并允许他们在任何其他日期打卡。
逻辑
if (user and createddate doesn't exist)
{
allow clock in
}
else if user and createddate exists)
{
deny clock in, show an error message.
}
else if (user exists but createddate doesn't match any of the dates) -- to allow user to clock in on other days
{
allow clock in
}我有点纠结于如何做到这一点。
发布于 2019-04-30 16:50:43
检查以下脚本。这应该能达到你的目的-
IF NOT EXISTS(
SELECT * FROM clockin
WHERE CONVERT(VARCHAR, createddate, 101) = CONVERT(VARCHAR, GETDATE(), 101)
AND username = @Username
AND eventname = @b
)
BEGIN
--You can perform your Clocked steps here
PRINT 'Not Clocked Today'
END
ELSE
PRINT 'Already Clocked Today'https://stackoverflow.com/questions/55916623
复制相似问题