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,669 of 19,505   
   Tony Mountifield to David Portas   
   Re: SQL Server 2000 - how to do MAX(a,b)   
   10 Oct 09 22:07:14   
   
   From: tony@softins.clara.co.uk   
      
   In article ,   
   David Portas  wrote:   
   > "Tony Mountifield"  wrote in message   
   > news:hanm55$io8$1@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.   
   > >   
   >   
   > Try this:   
   >   
   > UPDATE foo SET x =   
   >  (SELECT MAX(col)   
   >   FROM (SELECT .... /* your subquery */   
   >   UNION ALL SELECT 0) t);   
      
   Thanks to all for the responses, but I like this one best - very clever!   
      
   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