You are here: Re: SQL statement to compare and return one aggregated value « MsSQL Server « IT news, forums, messages
Re: SQL statement to compare and return one aggregated value

Posted by Ed Murphy on 10/18/06 02:29

Pradeep wrote:

> In my table, I have two columns - ForecastSales and ActualSales. I need
> to write a query that returns me just one aggregate value (one row and
> one column). If sum(ActualSales - ForecastSales) is negative, I need to
> return "red." Otherwise, I need to return green.
>
> I looked at CASE statement. However, I could not figure out an
> efficient way to build this query. I would appreciate your help.

declare @TheValue decimal(15,2)
declare @TheResult varchar(5)

select @TheValue = (
select sum(ActualSales - ForecastSales)
from TheTable
)

select @TheResult = case
when @TheValue < 0 then 'red'
else 'green'
end

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация