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
 General SQL Server Forums
 New to SQL Server Programming
 problem with If in update

Author  Topic 

fabianus76
Posting Yak Master

191 Posts

Posted - 2008-06-22 : 19:07:02
Hello all !

I get an error with the following sql :


update recplus set QuantityInKg =
(
IF Quantity_Unit_ID = 4
Quantity_Val
ELSE

ElementWeight_Val * Quantity_Val
)

this is the error I get :

Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'IF'.
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near 'Quantity_Val'.

I would be glad if anyone could help me !

Regards,
Fabianus

my favorit hoster is ASPnix : www.aspnix.com !

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-06-22 : 19:25:01
Try with CASE instead.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-22 : 23:52:54
[code]update recplus
set QuantityInKg = case when Quantity_Unit_ID = 4
then Quantity_Val
else ElementWeight_Val * Quantity_Val
end[/code]

Go to Top of Page

fabianus76
Posting Yak Master

191 Posts

Posted - 2008-06-23 : 04:15:20
thanks a lot for your kind and quick support !
This solved my problem !

Regards,
Fabianus

my favorit hoster is ASPnix : www.aspnix.com !
Go to Top of Page
   

- Advertisement -