0

Is there any way to select from SQL Server by 'Queue, serie ...'.

For example I want to get some rows by using identifier.

I want to get rows ordered by like C, D, A, F

SELECT * 
FROM BRANCH 
WHERE IDENTIFIER IN ('C', 'D', 'A', 'F')

And this query turns rows order by random.

Maybe ordered as

  • 'F', 'D', 'A', 'C'

  • 'A', 'B', 'C', 'D'

How can I get the result set ordered as 'C', 'D', 'A', 'F'? I need this using for for xml path usage.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ahmet
  • 314
  • 5
  • 15

1 Answers1

4
SELECT b.*
FROM dbo.BRANCH b
JOIN (
    VALUES
        (1, 'C'),
        (2, 'D'),
        (3, 'A'),
        (4, 'F')
) c(ID, IDENTIFIER) ON c.IDENTIFIER = b.IDENTIFIER
ORDER BY c.ID
Devart
  • 119,203
  • 23
  • 166
  • 186
  • Is that possible for Oracle ? I mean not ordering. is there any using in pl sql like 'values' syntax – Ahmet Mar 23 '16 at 07:36
  • Check this - http://stackoverflow.com/questions/10747355/oracle-11g-unpivot-multiple-columns-and-include-column-name – Devart Mar 23 '16 at 09:09