i have a table #temp1(id, Name groupname ) and record
like this 1 R1 S
2 R3 S
3 R2 S
4 R4 D
5 R5 D
6 R6 K
7 R7 K
8 R8 L
9 R9 L
10 R10 L
11 R11 K

and i want to display record based on user defind sorting
order e.g.
1 R4 D
2 R5 D
3 R6 K
4 R7 K
5 R11 K
6 R1 S
7 R3 S
8 R2 S
9 R8 L
10 R9 L
11 R10 L

Answer Posted / ram birendra jha

SELECT
case name
When 'R4' then 1
When 'R5' then 2
When 'R6' then 3
When 'R7' then 4
When 'R11' then 5
When 'R1' then 6
When 'R3'then 7
When 'R2'then 8
When 'R8' then 9
When 'R9' then 10
When 'R10' then 11
END as Id,
name,groupname FROM Tempid
ORDER BY Id

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is not null constraint?

611


What is parameterized reports in ssrs ?

105


What is sqlservr.exe - process - sql server (sqlex?press)?

590


as a part of your job, what are the dbcc commands that you commonly use for database maintenance? : Sql server database administration

482


Can we perform backup restore operation on tempdb? : sql server database administration

579






What is difference between index and primary key?

576


What is indexing a document?

541


How to transfer data from a cursor to variables with a "fetch" statement?

575


Why we use trigger in sql server with example?

504


Scalability, Availability, Integration with internet, etc.)?

2424


Explain the difference between clustered and non-clustered index?

529


How to connect to SQL Azure Database by using sqlcmd?

110


Can we use having clause without group by?

541


What are the differences between DDL, DML and DCL in SQL?

750


Is null vs coalesce?

496