June 11, 2010 at 2:50 am
I have table which have 'A' column store data such 1, 2, 3, 4
I use select statement and order by 'A' but I want the result order like 1, 3, 2, 4
please help
384870070181D000011
384890070181D000011
385000170021D000011
385010170022D000011
385020170022D000011
384920170022D000011
384930170022D000011
384970070183D000011
385040070183D000011
384990070183D000011
385060070183D000011
385050170024D000011
384980170024D000011
384960170024D000011
385030170024D000011
I expected result like
384870070181D000011
384890070181D000011
385000170021D000011
384970070183D000011
385040070183D000011
384990070183D000011
385060070183D000011
385010170022D000011
385020170022D000011
384920170022D000011
384930170022D000011
385050170024D000011
384980170024D000011
384960170024D000011
385030170024D000011
June 11, 2010 at 2:58 am
DROP TABLE #Table
CREATE TABLE #Table (A INTEGER)
INSERT INTO #Table (A)
SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4
SELECT *
FROM #Table
ORDER BY
CASE
WHEN A = 1 THEN 1
WHEN A = 2 THEN 3
WHEN A = 3 THEN 2
WHEN A = 4 THEN 4
END
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
June 11, 2010 at 4:00 am
Thanks Bro
June 11, 2010 at 4:09 am
The sample data is a little late but never mind - what are the column names?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply