下面的代码运行良好,但我觉得它太长了,我想在删除它之前将字段“MealNo”中的值“1”删除到具有字段 MealNo=2 的行中
下面的代码完成了这项工作,但我看到它很长,有什么办法可以缩短它吗?特别是在“哪里”之后
if ((SELECT MealNo FROM [Temp_Food_TBL] WHERE [AutoNo] = @AutoNo) = 1)
BEGIN
Update [Temp_Food_TBL]
SET
MealNo = 1
Where
MealNo = 2
AND
PersonID = (SELECT PersonID FROM [Temp_Food_TBL] WHERE [AutoNo] = @AutoNo)
AND
MealTime = (SELECT MealTime FROM [Temp_Food_TBL] WHERE [AutoNo] = @AutoNo)
AND
MealDate = (SELECT MealDate FROM [Temp_Food_TBL] WHERE [AutoNo] = @AutoNo)
END
DELETE FROM [Temp_Food_TBL]
WHERE
[AutoNo] = @AutoNo