ruffone
ruffone

Reputation: 23

Use a stored procedure in IF EXISTS method instead of select statement

I would love to reuse a stored procedure in this situation instead of rewriting the code

    IF EXISTS (EXEC [dbo].[SP_JobStop_FindJobByAll] WITH (updlock,serializable)
        --IF EXISTS (SELECT * FROM [EZPassDataDB].[dbo].[JobPass] AS [o] WITH (updlock,serializable)
        --WHERE [o].[jobNumber] = @jobNumber

Upvotes: 0

Views: 52

Answers (1)

David Browne - Microsoft
David Browne - Microsoft

Reputation: 88881

You can load the resultset from the stored procedure into a temp table or table variable with INSERT ... EXEC, eg:

declare @jobs table(...)

insert into @jobs(...)
exec [dbo].[SP_JobStop_FindJobByAll]

if exists (select * from @jobs)
begin
  . . .
end

Upvotes: 1

Related Questions