我在SQL Server中尝试使用存储过程进行验证。但存储过程无效。
我有一张桌子room
。我从房间桌上得到了备份作为房间备份。我试图在SQL Server中使用存储过程验证,当room
表记录大于房间备份表记录时,所以我需要重写房间备份表。我尝试了以下代码,但它无法正常工作
CREATE PROC Sp_verify
AS
IF (SELECT Count()
FROM Room) > (SELECT Count()
FROM RoomBackup)
BEGIN
DELETE RoomBackup;
INSERT INTO RoomBackup
(R_No,
R_Type,
R_stus,
AP_No,
P_Name,
R_Charge)
SELECT R_No,
R_Type,
R_stus,
AP_No,
P_Name,
R_Charge
FROM Room;
END
请帮帮我
答案 0 :(得分:0)
修改程序如下:
IF ((SELECT Count(1)
FROM Room) > (SELECT Count(1)
FROM RoomBackup))
BEGIN
DELETE RoomBackup;
INSERT INTO RoomBackup
(R_No,
R_Type,
R_stus,
AP_No,
P_Name,
R_Charge)
SELECT R_No,
R_Type,
R_stus,
AP_No,
P_Name,
R_Charge
FROM Room;
END
Count
函数需要一个参数。 if
子句