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 |
|
rwlopez
Yak Posting Veteran
80 Posts |
Posted - 2006-09-20 : 17:54:36
|
| I am trying to incorporate some IF Statement logic into a SQL 2005 function, but I am having trouble with the syntax. Here is an example. Can someone assist me with this.BEGIN DECLARE @TestVariable MONEY SET @TestVariable= '' SELECT @TestVariable= TotalPaid - TotalSpent FROM Spending---------This is where I am having trouble---------------------------- IF @TestVariable < 0 Then @TestVariable = TotalPaid - TotalSpentEND RETURN @TestVariableEND |
|
|
timmy
Master Smack Fu Yak Hacker
1242 Posts |
Posted - 2006-09-20 : 17:59:16
|
| Not sure about 2005, but in 2000 you would replace the 'Then' with a 'BEGIN'HTH,Tim |
 |
|
|
rwlopez
Yak Posting Veteran
80 Posts |
Posted - 2006-09-20 : 18:38:44
|
| I am having trouble just getting that to work. Is there something wrong with this syntax. Yes I am using 2005. IF @TotalSpent > 0 BEGIN @TotalSpent = 100 END |
 |
|
|
timmy
Master Smack Fu Yak Hacker
1242 Posts |
Posted - 2006-09-20 : 19:17:57
|
| You'll want a SET statement in there:SET @TotalSpent = 100Easy trap to fall into when coming from other languages.... |
 |
|
|
|
|
|