Select with case-statement
Posted in 2010
Topics: General Discussion
I need some help with a (simple ?) query.
Query: (just and example)
======
select case
when tabauth[1,1] = 's' and tabauth[2,2] = 'u' and tabauth[3,3] =
'-' and tabauth[4,4] = 'i' and tabauth[5,5] = 'd' then 'Select, Update,
Insert, Delete'
end
from systabauth;
The problem is I have hardcoded this for 1 condition: if flags are
"su-id"
There can be many possible combinations:
su-i-
su---
su--d
...
...
etc.
Is there a way to simplify this query to cater for all possible
conditions, or do you have to hardcode for every possible combination ?
Dirk
How about this?
select case
when tabauth like 'su-%' then 'Select, Update,
Insert, Delete'
end
from systabauth;
You can also add additional conditions to it like
select case
when tabauth like 'su-%'
AND tabauth not like "su--d%"
then 'Select, Update,
Insert, Delete'
end
from systabauth;
-Manoj
From:
"Dc Dirk Moolman" <DIRK@za.ibm.com>
To:
ids@iiug.org
Date:
01/07/2010 07:30 AM
Subject:
Select with case-statement [18600]
Sent by:
ids-bounces@iiug.org
I need some help with a (simple ?) query.
Query: (just and example)
======
select case
when tabauth[1,1] = 's' and tabauth[2,2] = 'u' and tabauth[3,3] =
'-' and tabauth[4,4] = 'i' and tabauth[5,5] = 'd' then 'Select, Update,
Insert, Delete'
end
from systabauth;
The problem is I have hardcoded this for 1 condition: if flags are
"su-id"
There can be many possible combinations:
su-i-
su---
su--d
....
....
etc.
Is there a way to simplify this query to cater for all possible
conditions, or do you have to hardcode for every possible combination ?
Dirk
*******************************************************************************
Forum Note: Use "Reply" to post a response in the discussion forum.