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
What is not null constraint?
What is parameterized reports in ssrs ?
What is sqlservr.exe - process - sql server (sqlex?press)?
as a part of your job, what are the dbcc commands that you commonly use for database maintenance? : Sql server database administration
Can we perform backup restore operation on tempdb? : sql server database administration
What is difference between index and primary key?
What is indexing a document?
How to transfer data from a cursor to variables with a "fetch" statement?
Why we use trigger in sql server with example?
Scalability, Availability, Integration with internet, etc.)?
Explain the difference between clustered and non-clustered index?
How to connect to SQL Azure Database by using sqlcmd?
Can we use having clause without group by?
What are the differences between DDL, DML and DCL in SQL?
Is null vs coalesce?