Conditional Order By for stored procedure
Date: 11/04/05
(Asp Dot Net) Keywords: asp, sql, web
ORDER BY CASE WHEN @OrderBy = '1' THEN NEWID()
WHEN @OrderBy = '2' THEN (tblaccommodation.name)
WHEN @OrderBy = '3' THEN (tblaccommodation.FromDT)
END
This is the order by conditional statement i am using
to order an asp.net result set but it keeps returning
this error below for the name feild (text) and sql
server throws up a unique identifier error for FromDT
(a datetime) which asks for the convert fuction to be
used but each of these three works without the Case
statement without any trouble.
The asp.net error for name feild
Syntax error converting from a character string to uniqueidentifier.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Syntax error converting from a character string to uniqueidentifier.
Source Error:
Line 220: ' Create and Fill the DataSet
Line 221: Dim myDataSet As New DataSet()
Line 222: myCommand.Fill(myDataSet)
Line 223:
Line 224: ' Return the DataSet
Source File: c:\inetpub\wwwroot\devotion2motion.com\CodeBehind\AccomSearch.vb Line: 222
Source: http://www.livejournal.com/community/aspdotnet/46138.html