Imagination
Member
Hi!
I'm looking at a table to see if there are 2 Group Variables in it. Based on if one or both are in the table, i'm trying to create a sql row based on 3 function id's. I'm am just wondering if there is a simple way to do it then what i'm doing (ie: get rid of the unions).
Thanks!
declare @GRPREV varchar(12)
select @GRPREV = groupid from [function] where groupid = 'GRPREV'
declare @GRPREC varchar(12)
select @GRPREC = groupid from [function] where groupid = 'GRPREC'
SELECT 'A' as product, 'REV' as functionid, 'Reverse' as description, 'sys' as groupid,
(Case when exists (select * from userfunction where product = 'A' and functionid = 'REV') then 1 else 0 end) as entitled
WHERE @GRPREV = 'GRPREV'
UNION
SELECT 'A' as product, 'REC' as functionid, 'Record' as description, 'sys' as groupid,
(Case when exists (select * from userfunction where product = 'A' and functionid = 'REC') then 1 else 0 end) as entitled
WHERE @GRPREC = 'GRPREC'
UNION
SELECT 'A' as product, 'VerifyRev' as functionid, 'Verify Reverse/Record' as description, 'sys' as groupid,
(Case when exists (select * from userfunction where product = 'A' and functionid = 'VerifyRev') then 1 else 0 end) as entitled
WHERE (@GRPREC = 'GRPREC' or @GRPREV = 'GRPREV')
I'm looking at a table to see if there are 2 Group Variables in it. Based on if one or both are in the table, i'm trying to create a sql row based on 3 function id's. I'm am just wondering if there is a simple way to do it then what i'm doing (ie: get rid of the unions).
Thanks!
declare @GRPREV varchar(12)
select @GRPREV = groupid from [function] where groupid = 'GRPREV'
declare @GRPREC varchar(12)
select @GRPREC = groupid from [function] where groupid = 'GRPREC'
SELECT 'A' as product, 'REV' as functionid, 'Reverse' as description, 'sys' as groupid,
(Case when exists (select * from userfunction where product = 'A' and functionid = 'REV') then 1 else 0 end) as entitled
WHERE @GRPREV = 'GRPREV'
UNION
SELECT 'A' as product, 'REC' as functionid, 'Record' as description, 'sys' as groupid,
(Case when exists (select * from userfunction where product = 'A' and functionid = 'REC') then 1 else 0 end) as entitled
WHERE @GRPREC = 'GRPREC'
UNION
SELECT 'A' as product, 'VerifyRev' as functionid, 'Verify Reverse/Record' as description, 'sys' as groupid,
(Case when exists (select * from userfunction where product = 'A' and functionid = 'VerifyRev') then 1 else 0 end) as entitled
WHERE (@GRPREC = 'GRPREC' or @GRPREV = 'GRPREV')