December 16, 2013 at 9:14 am
Hello all,
I have an existing select query with where clause as:
and g.ID in
(Select ID From Groups where GroupName = 'SVP - LATAM'
Union
Select ID From Groups where Sub = 1 )
I need to add another condition here:
If RoleID= 5 then the existing filter is ignored otherwise include the existing filter, so it is something like:
and (Case @RoleID <> 5 then g.ID in
(Select ID From Groups where GroupName = 'SVP - LATAM'
Union
Select ID From Groups where Sub = 1 )
Thanks.
December 16, 2013 at 9:23 am
I think you'd just extend the WHERE statements in the query to also compare the @RoleId :
how about this?
and g.ID in
(Select ID From Groups
where GroupName = 'SVP - LATAM'
AND @RoleID <> 5
Union
Select ID From Groups
where Sub = 1
AND @RoleID <> 5 )
Lowell
December 16, 2013 at 9:24 am
There are several ways of doing that.
and ( @RoleID = 5
OR g.ID in
(Select ID From Groups where GroupName = 'SVP - LATAM'
Union ALL
Select ID From Groups where Sub = 1 )
)
OR
and ( g.ID in
(Select ID From Groups where GroupName = 'SVP - LATAM'
Union ALL
Select ID From Groups where Sub = 1
Union ALL
SELECT g.ID
)
)
Or you could use dynamic code. http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/
December 16, 2013 at 9:33 am
Thanks guys, I was thinking it too complex. :w00t:
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply