Forums

This topic is locked

SQL and ORDER BY

Posted 26 Jun 2002 21:56:26
1
has voted
26 Jun 2002 21:56:26 aegis kleais posted:
When developing for a website of mine, I have 5 pages to each section.

Page, page_view, page_add, page_edit and page_delete

On PAGE, I list a recordset and all of it's fields. I also provide a dropdown box that is populated with the name of each field in the recordset and next to them are 2 buttons, 1 saying ASC and the other saying DESC.

Suppose the user selects fldID from the dropdown and presses DESC...the page will goto:

page.asp?srt=fldID&ord=DESC

And of course, the page itself, reads the QueryString and creates the recordset again, this time sorting by fldID and ordering by DESC.

Works great, but here's the problem.

I selected fldName and pressed ASC and got an error saying that text, ntext and image cannot be used in ORDER BY clauses.

REALLY!?!? I know that fldName is indeed, a text datatype on the server, but why can't SQL sort that field alphabetically? Anyways, here's my code; your help is much appreciated!

SELECT * FROM dbo.tblRegions ORDER BY MM_sort MM_ord

---------------------------------

MM_sort - Default Value = fldID (numeric) - Runtime Value = Request.QueryString("srt"
MM_ord - Default Value = ASC - Runtime Value = Request.QueryString("ord"

Replies

Replied 28 Jun 2002 09:41:55
28 Jun 2002 09:41:55 Viktor Farcic replied:
Change text to varchar and ntext to nvarchar. If I'm not mistaking, varchar can hold up to 8.000 characters.

<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
When developing for a website of mine, I have 5 pages to each section.

Page, page_view, page_add, page_edit and page_delete

On PAGE, I list a recordset and all of it's fields. I also provide a dropdown box that is populated with the name of each field in the recordset and next to them are 2 buttons, 1 saying ASC and the other saying DESC.

Suppose the user selects fldID from the dropdown and presses DESC...the page will goto:

page.asp?srt=fldID&ord=DESC

And of course, the page itself, reads the QueryString and creates the recordset again, this time sorting by fldID and ordering by DESC.

Works great, but here's the problem.

I selected fldName and pressed ASC and got an error saying that text, ntext and image cannot be used in ORDER BY clauses.

REALLY!?!? I know that fldName is indeed, a text datatype on the server, but why can't SQL sort that field alphabetically? Anyways, here's my code; your help is much appreciated!

SELECT * FROM dbo.tblRegions ORDER BY MM_sort MM_ord

---------------------------------

MM_sort - Default Value = fldID (numeric) - Runtime Value = Request.QueryString("srt"
MM_ord - Default Value = ASC - Runtime Value = Request.QueryString("ord"
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Viktor Farcic
www.farcic.com
TalkZone Manager

Reply to this topic