如何取得SELECT COUNT(*) 的值并判断
在存储过程中如何根据 SELECT COUNT(*) 的值来做判断:
DECLARE @CountID int
SELECT COUNT(*) AS @CountID FROM Accounts_Comments WHERE UserID = @UserID
IF @CountID=0
ELSE
这样好像不行,能用:
SET @CountID = (SELECT COUNT(*) AS @CountID FROM Accounts_Comments WHERE UserID = @UserID〗
IF @CountID=0
ELSE
求一个解答。
[解决办法]
DECLARE @CountID int SELECT @CountID=COUNT(*) FROM Accounts_Comments WHERE UserID = @UserID IF @CountID=0 ELSE
[解决办法]
IF (SELECT COUNT(1) FROM Accounts_Comments WHERE UserID = @UserID)=0 PRINT 'No Data for '+@UserIDelse...
[解决办法]
--日,这个地方count(*)要改,不然会一直存在一条记录,忘记改了IF not exists (select 1 from Accounts_Comments WHERE UserID = @UserID) ELSE