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 Andy Hassall on 10/14/81 11:26

On Mon, 12 Sep 2005 11:50:52 +0300, "Kimmo Laine"
<eternal.erectionN05P@Mgmail.com> wrote:

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

The Standard (with a capital 'S', i.e. SQL92) statement is CASE.

SELECT CASE
WHEN dsum > 100 THEN 100
ELSE dsum
END dsum_2
from view1

If this doesn't work, ask in an MSSQL group.

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

 

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

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