|
-
July 18th, 2005, 08:19 AM
#1
Case statement in Where clause / Informix
I need a little help with these case statments in my where clause. I don't need to display the results of the case statements, but I do need to put them in my where clause. Any help??
select distinct(r.studentid), r.studentname, r.building,
case when r.currcode like'D%' or r.currcode like 'W%' then rc.dual1 else r.currcode end Currcode,
case when r.currcode like'D%' or r.currcode like 'W%' then rc.dual2 else '' end Dual2
from reg r, bldgtype b, regtb_curr_code rc
where
r.status = 'A' and
b.type = 1 and
r.building = b.bldg and
r.currcode = rc.code and
(
case when r.grade in ('KA','KP','KF') then 'KG' else r.grade end or
case when r.grade in ('PA','PP','PK') then 'PK' else r.grade end
)
(r.building || '*' || trim(r.grade) || '*' || trim(r.currcode)) not in
(select s.bldg || '*' || trim(s.grade) || '*' || trim(s.prog) from seats s where seats >0)
Last edited by zombie_man23; July 18th, 2005 at 10:55 AM.
-
July 18th, 2005, 08:44 AM
#2
Re: Case statement in Where clause / Informix
Code:
case when r.grade in ('KA','KP','KF') then 'KG' else r.grade end
case when r.grade in ('PA','PP','PK') then 'PK' else r.grade end
Does any of these evaluate to someting you need in a where clause?
- petter
-
July 18th, 2005, 08:50 AM
#3
Re: Case statement in Where clause / Informix
Yes. The results of those case statements goes into the next line of the query for the r.grade comparison:
-----------------------here--------------------------------
(r.building || '*' || trim(r.grade) || '*' || trim(r.currcode)) not in
(select s.bldg || '*' || trim(s.grade) || '*' || trim(s.prog) from seats s where seats >0)
-
July 18th, 2005, 09:09 AM
#4
Re: Case statement in Where clause / Informix
But neither the "CASE", nor the "NOT IN" expression are valid...
The [NOT] IN should be on the form:
Code:
test_expression [ NOT ] IN
(
subquery
| expression [ ,...n ]
)
Maybe you could explain in plain english what you're trying to accomplish?
- petter
-
July 18th, 2005, 09:17 AM
#5
Re: Case statement in Where clause / Informix
When the case statements are taken out the query works fine. What I am trying to do is compare the building, grade, and program between two tables. What the case statements is being used for is, if the student is in KA, KP, or KF the r.grade value should be KG. Or, if the student is in PA, PP, or PK the r.grade value needs to be PK, otherwise, the r.grade value is the original from the database.
-
July 18th, 2005, 10:54 AM
#6
Re: Case statement in Where clause / Informix
I have resolved my problem. Thanks for the help though!!!
Here is what I came up with.
(r.building || '*' || trim(case when r.grade in ('KA','KP','KF') then 'KG' when r.grade in ('PA','PP','PK') then 'PK' else r.grade end) || '*' || trim(r.currcode)) not in
(select s.bldg || '*' || trim(s.grade) || '*' || trim(s.prog) from seats s where seats >0)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|