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 |
|
mufasa
Yak Posting Veteran
62 Posts |
Posted - 2004-01-22 : 11:06:41
|
HiI am having problems returning conditional values. Below is the statement I am trying to use.IF((dbo.[Com-Pen Sales].MTYSales > dbo.[Com-Pen Sales].MTYBudget) THEN dbo.BonusGrid.AsstBudgetBonus ELSE 0)What I am trying to do is that if MTYSales is greater than MTYBudgetReturn the value linked in AsstBudgetBonusUnfortunately I am used to using MS Access and having a hard time using If Else statements in SQL.Thanks for any helpMufasa  |
|
|
pap
Starting Member
13 Posts |
Posted - 2004-01-22 : 11:12:55
|
quote: Originally posted by mufasa HiI am having problems returning conditional values. Below is the statement I am trying to use.IF((dbo.[Com-Pen Sales].MTYSales > dbo.[Com-Pen Sales].MTYBudget) THEN dbo.BonusGrid.AsstBudgetBonus ELSE 0)What I am trying to do is that if MTYSales is greater than MTYBudgetReturn the value linked in AsstBudgetBonusUnfortunately I am used to using MS Access and having a hard time using If Else statements in SQL.Thanks for any helpMufasa 
You can do this with:IF((dbo.[Com-Pen Sales].MTYSales > dbo.[Com-Pen Sales].MTYBudget)beginreturn dbo.BonusGrid.AsstBudgetBonus endelsebeginreturn 0endpap |
 |
|
|
raymondpeacock
Constraint Violating Yak Guru
367 Posts |
Posted - 2004-01-22 : 11:13:44
|
| Try using the CASE statement. Something likeSELECT CASE WHEN dbo.[Com-Pen Sales].MTYSales > dbo.[Com-Pen Sales].MTYBudget) THEN dbo.BonusGrid.AsstBudgetBonus ELSE 0ENDRaymond |
 |
|
|
mufasa
Yak Posting Veteran
62 Posts |
Posted - 2004-01-22 : 11:37:47
|
| Thanks guys I used the second suggestion with CASE, works fineThanks Again |
 |
|
|
|
|
|