Ordering based on a case statement

Posts   
 
    
aledeniz
User
Posts: 1
Joined: 31-Mar-2006
# Posted on: 31-Mar-2006 19:41:46   

Dear all, I've got a view in SQL Server 2005 (in readcommitted rowversioning mode), whose query statement looks as the following:

SELECT TOP (100) PERCENT l.ID, l.Name 
FROM    
    dbo.Location l 
    INNER JOIN dbo.LocationType lt 
        ON l.TypeID = lt.ID
WHERE
    lt.Name = 'Country'
ORDER BY 
CASE 
    l.ID 
        WHEN 225 THEN 2 
        WHEN 161 THEN 1 
END DESC, 
l.Name

I did map the view with an entity, but unfortunately when fetching the data in a collection, it is ordered by ID (as happens to be also if I issue a "select * from vCountry" on SSMS, anyway). I thought I may fix that if I could translate the query on LLBLGen Pro, but I couldn't find any documentation showing a support for the case statement. Is it there? Any alternative option (apart from the trivial "adding a sort column", of course)?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 01-Apr-2006 03:26:48   

I don't think you'll be able to easily add a case statement. Why would you not use a sort clause when fetching the collection? It appears that the information would be in the order that you would want, just with 225 and 161 as the values. Here's a link about the cases. http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=5604&HighLight=1