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 / getaway

Very vague question!

The asker did not give an explanation of the desired sorting rule. Without that the closest answer is to sort based on Order by groupname, name

Of course specifying the query's output through CASE..WHEN.. is the "smartest" idea. If you give me this answer at the job interview, I positively won't hire you. As it was mentioned in answer #4, what if the table has 1000 rows? And in a week - 5000? How you gonna manage your query?

Good luck.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is index in an assignment?

526


How many databases instances are there in sql server 2000?

571


What is the default fill factor value?

574


Can you please explain the difference between function and stored procedure?

536


What is the difference between seek predicate and predicate?

578






How to verify a login name with sqlcmd tool?

589


Define self join in sql server joins?

514


What are horizontal and vertical scaling?

144


What is SQL Azure Fabric?

92


What is the purpose of linked server configuration in sql server?

544


What is data modeling and Reterminal integrity?

1482


Do you know what is raid and what are different types of raid configurations? : SQL Server Architecture

537


What is @@rowcount in sql?

552


How to get all stored procedures in sql server?

502


How can I get data from a database on another server?

505