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.
| Author |
Topic |
|
neolegionar
Starting Member
3 Posts |
Posted - 2009-04-25 : 11:01:55
|
| Hello guysi have 2 tables : user & compartmentUSER:id - NUMBER PKname - VARCHAR2id_compartment - NUMBER - REFERENCE TO COMPARTMENT->idCOMPARTMENTid - NUMBER PKname - VARCHAR2id_chief - NUMBER - REFERENCE TO USER->idNow i wanna make a query like thisSELECT c.id, c.name, ??? FROM compartment c, user unow 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 welcomeThanks 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 IsChieffrom compartment cjoin 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. |
 |
|
|
neolegionar
Starting Member
3 Posts |
Posted - 2009-04-25 : 11:35:00
|
| webfred thanks a lot ! Very helpful! |
 |
|
|
|
|
|