试图解决这个问题但不确定如何做到这一点。
我需要首先检查表格事件中有人值守和条形码是否正确,如果是,它会更新。
如果没有,它需要检查什么不正确:
如果出席不正确,请选择@Err
如果条形码不正确,请选择@ Err2
我不确定这是否是最佳方法。 提前谢谢。
-- Returns scan details
DECLARE @Err nvarchar(Max) = 'Already scanned'
DECLARE @Err2 nvarchar(Max) = 'Barcode not found'
IF (EXISTS(SELECT * FROM [Test].[dbo].[Events] WHERE Attended = '0' AND Barcode = @scan))
BEGIN
UPDATE [Test].[dbo].[Events] SET Attended = GETDATE() WHERE Barcode = @scan
SELECT Title, Forename, Surname, Constituency, Category, Barcode, EventDate, EventName, Attended FROM [Test].[dbo].[Events] WHERE Barcode = @scan
END
ELSE
BEGIN
-- select @Err
END
答案 0 :(得分:0)
我认为你需要这样的东西:
-- Returns scan details
DECLARE @Err nvarchar(Max) = 'Already scanned'
DECLARE @Err2 nvarchar(Max) = 'Barcode not found'
IF (EXISTS(SELECT * FROM [Test].[dbo].[Events] WHERE Attended = '0' AND Barcode = @scan))
BEGIN
UPDATE [Test].[dbo].[Events] SET Attended = GETDATE() WHERE Barcode = @scan
SELECT Title, Forename, Surname, Constituency, Category, Barcode, EventDate, EventName, Attended FROM [Test].[dbo].[Events] WHERE Barcode = @scan
END
ELSE IF (EXISTS(SELECT * FROM [Test].[dbo].[Events] WHERE Barcode = @scan))
BEGIN
select @Err
END
ELSE
BEGIN
SELECT @Err2
END
问候。