You are here: Re: using 'IF' in a query (MSSQL) « PHP SQL « IT news, forums, messages
Re: using 'IF' in a query (MSSQL)

Posted by Stefan Rybacki on 10/14/39 11:26

Kimmo Laine wrote:
> This is fucking ridiculous, but I can't seem to get this working.... I want
> to use if-statement inside a query. I remember clearly that something like
> this would actually work in MySQL, but so far I haven't got it working in
> MSSQL.
>
> Trying something like
> "SELECT IF(dsum > 100, 100, dsum) as dsum_2 from view1"
>
> Meaning, that if the particular row has dsum larger than 100, then output
> 100, but if it's less than 100, then output whatever dsum is. Doesn't work.
> Parse errors are all I get. I'm basicly trying to select the smaller of 100
> and dsum. dsum is something between 0...120.
>
> Like this:
> dataset | result of select
> dsum | dsum_2
> ---------------
> 100 | 100
> 50 | 50
> 120 | 100
> 75 | 75
> 105 | 100
>
>
> Thanks in advance
>

Maybe MSSQL Server supports UNION?

This way you could try something like this:

SELECT dsum FROM view1 WHERE dsum<=100
UNION
SELECT 100 as dsum FROM view1 WHERE dsum>100

Stefan

 

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

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