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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help with IF/ELSE or Case

Author  Topic 

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2008-04-08 : 06:56:46
I am trying to write the following using either an if/else or case, any help would be aprreciated.

Set the OPPORTUNITY.account_manager_override to false when the COMPANY.account_manager = 'xxx'. In all other cases, set the OPPORTUNITY.account_manager_override to true. Sounds simple enough....

This may help:
select opportunity_name, o.account_manager_id opp_manager, o.account_manager_override opp_override,
co.account_manager_id company_manager, co.account_manager_override company_override
from opportunity o
inner join company co on co.company_id = o.company_id
where co.account_manager_id = xxx

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2008-04-08 : 07:00:23
Use a case.
Go to Top of Page

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2008-04-08 : 07:21:25
I suspected case, any coding samples would be appreciated.
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-04-08 : 07:35:33
[code]Case when COMPANY.account_manager = 'xxx' then 0 else 1 end as account_manager_override[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2008-04-08 : 07:53:58
Great, ended up with somthing like this....

UPDATE o
SET o.account_manager_override =
CASE
WHEN (co.account_manager_id = 1234)
THEN 0
ELSE 1
END
from opportunity o
inner join company co on co.company_id = o.company_id
where opportunity_name = 'Test'
Go to Top of Page
   

- Advertisement -