1-ый вариант:
CREATE PROCEDURE [******].[****]
@GroupId BIGINT,
@EventId BIGINT,
@Exist BIT OUT
AS
BEGIN
if EXISTS(Select * From SimulatedResult.EventForSimulateGroup s
WHERE s.GroupId = @GroupId and s.EventId = @EventId)
BEGIN
SET @Exist = 1;
END
ELSE
BEGIN
SET @Exist = 0;
END
END
GO
-- Вызов процедуры.
DECLARE @GroupId BIGINT;
DECLARE @EventId BIGINT;
DECLARE @Exist BIT;
EXEC [******].[****] @GroupId, @EventId, @Exist OUT;
SELECT @Exist;
2-ой вариант:
-- Вызов процедуры.
CREATE PROCEDURE [******].[****]
@GroupId BIGINT,
@EventId BIGINT
AS
--DECLARE @Exist BIT
BEGIN
if EXISTS(Select * From SimulatedResult.EventForSimulateGroup s
WHERE s.GroupId = @GroupId and s.EventId = @EventId)
BEGIN
SELECT [Exists] = CAST(1 AS BIT)
END
ELSE
BEGIN
SELECT [Exists] = CAST(0 AS BIT)
END
END
GO
-- Вызов процедуры.
DECLARE @T TABLE ([Exists] BIT)
DECLARE @GroupId BIGINT;
DECLARE @EventId BIGINT;
INSERT INTO @T
EXEC [******].[****] @GroupId, @EventId;
SELECT * FROM @T
3-ий вариант:
CREATE PROCEDURE [******].[****]
@GroupId BIGINT,
@EventId BIGINT
AS
BEGIN
if EXISTS(Select * From SimulatedResult.EventForSimulateGroup s
WHERE s.GroupId = @GroupId and s.EventId = @EventId)
BEGIN
RETURN 1;
END
ELSE
BEGIN
RETURN 0;
END
END
GO
-- Вызов процедуры.
DECLARE @GroupId BIGINT;
DECLARE @EventId BIGINT;
DECLARE @Exists INT;
EXEC @Exists = [******].[****] @GroupId, @EventId;
SELECT CAST(@Exists AS BIT);