我有一个这样的简单表:
EmpId name Gen
----------------------
1 john 1
2 Ben 2
我写了一个简单的存储过程:
ALTER PROCEDURE GetCountEmployeeData
@empId INT
AS
BEGIN
DECLARE @gen INT
SELECT
@gen = Gen, EmpId = COUNT(EmpId)
FROM
Employee
WHERE
EmpId = @empId
END
如果我的计数不为空,那么我只想显示数据 - 否则我想显示"没有数据存在"
答案 0 :(得分:0)
希望这会对你有所帮助!您也可以通过传递参数或消息来返回您的计数。
DECLARE @msgToBeReturned varchar(1024);
declare @yourCount int
select @yourCount = count(*) FROM tbl_registration WHERE id = 121212
IF @yourCount > 0
BEGIN
SET @msgToBeReturned = 'found'
END
ELSE
BEGIN
SET @msgToBeReturned = 'not found'
END
select @msgToBeReturned
--return @msgToBeReturned