Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Answers were Sorted based on User's Feedback



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..

Answer / veeresh kethari

SELECT ROW_NUMBER() OVER(ORDER BY GROUPNAME ASC) ID
,NAME,GROUPNAME FROM REC ORDER BY GROUPNAME

Is This Answer Correct ?    2 Yes 0 No

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..

Answer / pradip jain

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

Is This Answer Correct ?    3 Yes 2 No

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..

Answer / pradip jain

Hi Ram, what new you are done man?
you have posted same answer as me.

Is This Answer Correct ?    0 Yes 0 No

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..

Answer / praveen kumar

this is not right query beacuse if table contain 1000
record then you need to give 1000 condition .so it is not
right answer

Is This Answer Correct ?    0 Yes 0 No

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..

Answer / alka

select id,name, groupname from #temp1
Order by groupname,name

Is This Answer Correct ?    0 Yes 0 No

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..

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

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..

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

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..

Answer / archana

Select * from #emp Order by id,Groupname

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More SQL Server Interview Questions

Well sometimes sp_reanmedb may not work you know because if some one is using the db it will not accept this command so what do you think you can do in such cases?

2 Answers  


Mention the 3 ways to get a count of the number of records in a table.

0 Answers  


why cluster and non clusterindex are used in sqlserver 2000? explain with example

1 Answers  


when you create a database how is it stored? : Sql server database administration

0 Answers  


What does the on delete cascade option do?

0 Answers  


How to create a trigger for insert only?

0 Answers  


How to find the latest updated value in a table without sending any parameters to that query

2 Answers  


what is extended StoreProcedure ?

3 Answers   Satyam,


PC(code, model, speed, ram, hd, cd, price) Find the hard drive sizes that are equal among two or more PCs.

6 Answers   APX,


explain different types of cursors? : Sql server database administration

0 Answers  


What is an execution plan?

0 Answers  


What is the difference between stored procedure and user defined functions?

0 Answers  


Categories