home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 17,667 of 19,505   
   Tony Mountifield to All   
   SQL Server 2000 - how to do MAX(a,b) or    
   09 Oct 09 15:51:01   
   
   From: tony@softins.clara.co.uk   
      
   I have scoured the online TSQL manual at MSDN and haven't found the   
   answer to this question.   
      
   In SQL Server 2000, how can I do MAX(a,b), GREATEST(a,b), MIN(a,b) or   
   LEAST(a,b) without needing to evaluate both of the arguments twice?   
      
   CASE WHEN a < b THEN b ELSE a END is not suitable, because one of the   
   arguments is a sub-select.   
      
   What I am trying to do is something like this:   
      
   UPDATE foo SET x = MAX(0, x - (SELECT ......))   
      
   or this:   
      
   UPDATE foo SET x = x - MIN(x, (SELECT .....))   
      
   in order to prevent x going negative.   
      
   Any hints would be much appreciated!   
      
   Cheers   
   Tony   
   --   
   Tony Mountifield   
   Work: tony@softins.co.uk - http://www.softins.co.uk   
   Play: tony@mountifield.org - http://tony.mountifield.org   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca