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

Posted by Kimmo Laine on 10/14/52 11:26

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

--
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]


Удаленная работа для программистов  •  Как заработать на 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

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