November 4, 2004 at 1:48 pm
UPDATE Table
SET qty_total = start_qty - end_qty
But, if qty_total ends up being negative, I want to update with a 0.
November 4, 2004 at 1:57 pm
You can use a CASE expression for this:
UPDATE Table
SET qty_total = CASE WHEN (start_qty - end_qty) < 0 THEN 0 ELSE (start_qty - end_qty) END
--
Adam Machanic
whoisactive
November 4, 2004 at 1:59 pm
What about
UPDATE Table
SET qty_total =
case when start_qty - end_qty < 0 then 0 else start_qty - end_qty end
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
November 4, 2004 at 2:00 pm
Damn, beaten by 2 minutes, Adam!
Should take a course in fast typing
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
November 5, 2004 at 7:38 am
No worries, you've got me beat by 3300 posts already ... Too bad there's not a prize
--
Adam Machanic
whoisactive
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply