In a stored procedure I have an IF condition to check whether the orgID exists in the result of the query to set the flag. What would be the correct syntax??
create procedure temp
(@TEMpID char(6)
)
declare @orgID char(3),flag char(1)
SET flag ='N'
BEGIN
set
@OrgID =(selecte orgID from table1)
IF @OrgID exists in ( select distinct(OrgID) from table2)
set flag = 'Y'
END
Begin
select p1, p2, p3, flag
from table3
END
Something like this:
Note: I think you have too many
begin/endblocks.You can write your proc as: