Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with a query

Author  Topic 

neolegionar
Starting Member

3 Posts

Posted - 2009-04-25 : 11:01:55
Hello guys
i have 2 tables : user & compartment

USER:
id - NUMBER PK
name - VARCHAR2
id_compartment - NUMBER - REFERENCE TO COMPARTMENT->id

COMPARTMENT
id - NUMBER PK
name - VARCHAR2
id_chief - NUMBER - REFERENCE TO USER->id

Now i wanna make a query like this

SELECT c.id, c.name, ??? FROM compartment c, user u

now in the ??? column i want to put the string 'checked' or 'unchecked' depending on the condition u.id = c.id_chief (Is user the chief of the compartment?). I dont know if is possible but any suggestions are welcome

Thanks a lot!

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-04-25 : 11:25:44
[code]
select
c.id,
c.name,
case when u.id=c.id_Chief then 'checked' else 'unchecked' end as IsChief
from compartment c
join user u on u.id_compartment = c.id
[/code]
Webfred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

neolegionar
Starting Member

3 Posts

Posted - 2009-04-25 : 11:35:00
webfred thanks a lot ! Very helpful!
Go to Top of Page
   

- Advertisement -