home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 17,732 of 19,505   
   m to Plamen Ratchev   
   Re: multiple column sort   
   08 Jan 10 13:17:04   
   
   From: miroslavsi@gmail.com   
      
   Thank you.   
      
   "Plamen Ratchev"  wrote in message   
   news:LtqdndqLsZOslNvWnZ2dnUVZ_rhi4p2d@speakeasy.net...   
   > You can also use CASE expressions. For example, if the data type of the   
   > columns is the same:   
   >   
   > ORDER BY CASE @column   
   >            WHEN 'column1' THEN column1   
   >            WHEN 'column2' THEN column2   
   >            WHEN 'column3' THEN column3   
   >          END   
   >   
   > If the data types are different then you have to use multiple CASE   
   > expressions:   
   >   
   > ORDER BY CASE @column WHEN 'column1' THEN column1 END,   
   >          CASE @column WHEN 'column2' THEN column2 END,   
   >          CASE @column WHEN 'column3' THEN column3 END   
   >   
   > But using dynamic SQL may be best as appropriate indexes on the ordering   
   > columns can be used more efficiently.   
   >   
   > --   
   > Plamen Ratchev   
   > http://www.SQLStudio.com   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca