|
Posted by Stefan Rybacki on 10/13/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]
|