Dynamic order by clause

Results 1 to 2 of 2

Thread: Dynamic order by clause

  1. #1
    Join Date
    Dec 1969

    Default Dynamic order by clause

    I have a dynamic order by in my stored proc.<BR><BR>Basically, it looks like this :<BR><BR>SET NOCOUNT ON <BR>...<BR>ORDER BY <BR> CASE <BR> WHEN @etat = 1 THEN no_camion_1<BR> WHEN @etat = 3 THEN nom_signataire<BR> ELSE date_demande <BR> END<BR>...<BR>SET NOCOUNT OFF<BR><BR>If I use it I got the following error for the @etat = 1 or 3<BR><BR>Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)<BR>[Microsoft][ODBC SQL Server Driver][SQL Server]<BR>Syntax error converting datetime from character string.<BR><BR>but if I use<BR> ELSE cast(date_demande as nvarchar) <BR><BR>there is no error, order for @etat 1 or 3 is fine but the order for other @etat on date_demande is not correct.<BR><BR>What wrong ?<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Dynamic order by clause

    Did you have any luck with this...I am having the same exact problem and can&#039;t figure it out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts