Reply to Re: SQL Pagination With Dynamic Order By

Your name:

Reply:


Posted by --CELKO-- on 04/04/07 16:48

>> Is there a way to do this in a single query with 2 different data types? <<

The CASE expression has to have one and only one data type, just like
any other expression in SQL and strongly typed languages.

The trick is to keep both columns and NULL one of the out or make it a
constant, somethign like this:

ROW_NUMBER() OVER (ORDER BY
CASE WHEN @x = 1 THEN decimal_col ELSE CAST(NULL AS DECIMAL(s,p)) END,
CASE WHEN @x = 2 THEN text_col ELSE CAST (NULL AS CHAR(n)) END) AS
sort_order

The casting is a bit redundant, but a nice reminder.

[Back to original 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

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