A SELECT question

  • I have a SELECT question:

    SUMMARY TABLE LAYOUT:

    ID char(16)

    ATTR varchar(6)

    LANG char(2)

    SOMETEXT ntext

    LANG is a language id; this can be specific (like EN) or neutral (like -).

    I want to select certain attr's given an ID; when the passed variable matches the LANG

    I want that row returned, otherwise the row with the LANG='-'... How do I do that?

  • Maybe something like...

    
    
    SELECT TOP 1 *
    FROM MyTable
    WHERE ID = @ID
    ORDER BY CASE WHEN LANG = '-' THEN 'b' ELSE 'a' END


    Cheers,
    - Mark

  • select *

    from MyTable

    where (@Lang = Lang and Id = @Id)

    or (Lang = '-')

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply