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 2000 Forums
 Transact-SQL (2000)
 IF Statement

Author  Topic 

mufasa
Yak Posting Veteran

62 Posts

Posted - 2004-01-22 : 11:06:41
Hi
I 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 MTYBudget
Return the value linked in AsstBudgetBonus

Unfortunately I am used to using MS Access and having a hard time using If Else statements in SQL.

Thanks for any help

Mufasa

pap
Starting Member

13 Posts

Posted - 2004-01-22 : 11:12:55
quote:
Originally posted by mufasa

Hi
I 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 MTYBudget
Return the value linked in AsstBudgetBonus

Unfortunately I am used to using MS Access and having a hard time using If Else statements in SQL.

Thanks for any help

Mufasa



You can do this with:

IF((dbo.[Com-Pen Sales].MTYSales > dbo.[Com-Pen Sales].MTYBudget)
begin
return dbo.BonusGrid.AsstBudgetBonus
end
else
begin
return 0
end

pap
Go to Top of Page

raymondpeacock
Constraint Violating Yak Guru

367 Posts

Posted - 2004-01-22 : 11:13:44
Try using the CASE statement. Something like

SELECT CASE
WHEN dbo.[Com-Pen Sales].MTYSales > dbo.[Com-Pen Sales].MTYBudget)
THEN dbo.BonusGrid.AsstBudgetBonus
ELSE 0
END




Raymond
Go to Top of Page

mufasa
Yak Posting Veteran

62 Posts

Posted - 2004-01-22 : 11:37:47
Thanks guys
I used the second suggestion with CASE, works fine

Thanks Again
Go to Top of Page
   

- Advertisement -