You are here: Re: SQL Pagination With Dynamic Order By « MsSQL Server « IT news, forums, messages
Re: SQL Pagination With Dynamic Order By

Posted by Ed Murphy on 04/04/07 15:52

rmturner76@gmail.com wrote:

> I have a need to perform pagination while using dynamic sorting. As
> an exmaple -
>
> SELECT TOP(10) * FROM (
> SELECT
> TextColumn,
> DecimalColumn,
> ROW_NUMER() OVER (
> ORDER BY
> CASE @x
> WHEN 1 THEN TextColumn
> WHEN 2 THEN DecimalColumn
> END
> DESC
> ) AS SortOrder
> FROM Table1
> ) AS Results WHERE SortOrder > ( 10 ) ORDER BY SortOrder
>
> This is obviously just some sample but an error is given because the
> data type of the 2 columns used in the order by are different. It
> works if I cast DecimalColumn to match the textcolumn but then the
> sorting is wrong. Is there a way to do this in a single query with 2
> different data types?

Try this:

WHEN 2 THEN
right(' '+cast(DecimalColumn as varchar(20)), 20)

 

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

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