|
Posted by Kimmo Laine on 10/06/67 11:26
"Stefan Rybacki" <stefan.rybacki@gmx.net> wrote in message
news:3okvp8F6du39U1@individual.net...
> 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
>
Works like a charm. Sadly, what Andy suggested as the standard way, didn't
work. MSSQL doesn't support such syntax. F*cking Microsoft piece of crap.
Gotta do it the wrong way then, as long as it works.
--
Welcome to Usenet! Please leave tolerance, understanding
and intelligence at the door. They aren't welcome here.
eternal piste erection miuku gmail piste com
Navigation:
[Reply to this message]
|