• Erin Ramsay (3/1/2013)


    Something like this maybe?

    select letter from

    (select 'a' letter

    union

    select 'b' letter

    union

    select 'c' letter

    union

    select 'd' letter

    union

    select 'e' letter)source

    order by (case letter when 'd' then 1when 'c' then 2 when 'b' then 3 when 'a' then 4 when 'e' then 5 end)

    Dear Erin,

    Thanks for suggestion. I think I didn't explain well. what I'm looking for is to run a SELECT against a table based on custom phrase. I have a temp table named @test1 like :

    DECLARE @test1 TABLE (letter varchar(1))

    INSERT INTO @test1(letter) VALUES('a')

    INSERT INTO @test1(letter) VALUES('b')

    INSERT INTO @test1(letter) VALUES('c')

    INSERT INTO @test1(letter) VALUES('d')

    INSERT INTO @test1(letter) VALUES('e')

    Now I need to "SELECT letter FROM @test1" based on order defined in this phrase 'd;c;b;a;e' to have a result like :

    [Letters]

    ----------

    d

    c

    b

    a

    e

    Any idea ?

    Thanks