| Author |
Topic |
|
sunitagoswami
Starting Member
10 Posts |
Posted - 2006-05-25 : 06:47:25
|
Can you please write a query as 1. The table goes as EmpID Emp Dept 123 Admin 789 Systems 989 IT 980 AccountsI want a Query which will resturn the EmpID in Ascending order while the Emp Dept in Descending order along with the RowNumber The Result will be RowNumber EmpID EmpDept 1 123 Systems 2 789 IT 3 980 Admin 4 989 AccountsThanks,Sunita Sunita |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-25 : 07:15:32
|
| Select EmpID, EmpDept from yourTable Order by EmpID ASC, EmpDept DESCReturn the result set to the front end application and number them thereMadhivananFailing to plan is Planning to fail |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-05-25 : 07:43:35
|
| ELECT (SELECT COUNT(i.EmpID) FROM Employee i WHERE i.EmpID >= o.EmpID) AS RowNumber, EmpID ,EmpDept FROM Employee oORDER BY RowNumberIf Debugging is the process of removing Bugs then i Guess programming should be process of Adding them. |
 |
|
|
sunitagoswami
Starting Member
10 Posts |
Posted - 2006-05-25 : 08:10:24
|
| Thanks,Even I got a solution but currently SQL SERVER is not installed please try thisselect Identity(int,1,1) as Rownumber, EmpID, EMPDept from table into table order by EmpID ASC, EmpDept DESCSunita |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-25 : 09:33:29
|
| chiragkhabaria, yours is not advisible for the table that has millions of rowssunitagoswami, yours is also not advisible for the same reason also that should beselect Identity(int,1,1) as Rownumber, EmpID, EMPDept into #temp from table order by EmpID ASC, EmpDept DESCMadhivananFailing to plan is Planning to fail |
 |
|
|
PSamsig
Constraint Violating Yak Guru
384 Posts |
Posted - 2006-05-25 : 10:03:59
|
And no one is actually giving the required result, but this one will (in 2005):SELECT D1.I, EmpID, EmpDeptFROM (SELECT ROW_NUMBER() OVER (ORDER BY EmpID ASC) AS I, EmpID FROM Emp) AS D1INNER JOIN (SELECT ROW_NUMBER() OVER (ORDER BY EmpDept DESC) AS I, EmpDept FROM Emp) AS D2ON D2.I = D1.I as I read the requirement was to sort the two coloumns independant of each other.-- This one's tricky. You have to use calculus and imaginary numbers for this. You know, eleventeen, thirty-twelve and all those. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-25 : 10:07:37
|
| >>And no one is actually giving the required result, but this one will (in 2005):The question didnt specify that she is using SQL Server 2005MadhivananFailing to plan is Planning to fail |
 |
|
|
PSamsig
Constraint Violating Yak Guru
384 Posts |
Posted - 2006-05-25 : 10:15:32
|
Hehehe true, but none of the others will, no matter which version of SQL Server is used -- This one's tricky. You have to use calculus and imaginary numbers for this. You know, eleventeen, thirty-twelve and all those. |
 |
|
|
PSamsig
Constraint Violating Yak Guru
384 Posts |
Posted - 2006-05-25 : 10:28:03
|
but to make 'madhivanan' happy:SELECT D1.I, EmpID, EmpDeptFROM (SELECT (SELECT COUNT(EmpID) FROM Emp i WHERE i.EmpID <= o.EmpID) AS I, EmpID FROM Emp o) AS D1INNER JOIN (SELECT (SELECT COUNT(EmpDept) FROM Emp i WHERE i.EmpDept >= o.EmpDept) AS I, EmpDept FROM Emp o) AS D2ON D2.I = D1.IORDER BY D1.I works both in 2000 and 2005.-- This one's tricky. You have to use calculus and imaginary numbers for this. You know, eleventeen, thirty-twelve and all those. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-25 : 10:35:19
|
| Well. But numbering should be done in front end applications if possibleMadhivananFailing to plan is Planning to fail |
 |
|
|
PSamsig
Constraint Violating Yak Guru
384 Posts |
Posted - 2006-05-25 : 10:47:40
|
| Unless the numbering is part of the solution, and in this case it is ....-- This one's tricky. You have to use calculus and imaginary numbers for this. You know, eleventeen, thirty-twelve and all those. |
 |
|
|
sunitagoswami
Starting Member
10 Posts |
Posted - 2006-05-26 : 01:27:02
|
| I got SQL SERVER 2000 installed today..Thanks a TON..PSamsig..Its great.. Sunita |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-26 : 03:42:30
|
quote: Originally posted by sunitagoswami I got SQL SERVER 2000 installed today..Thanks a TON..PSamsig..Its great.. Sunita
Where do you want to show the numbered data?MadhivananFailing to plan is Planning to fail |
 |
|
|
sunitagoswami
Starting Member
10 Posts |
Posted - 2006-05-26 : 08:27:26
|
| Madhivanan,Just out of curiosity .....Sunita |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-26 : 11:46:40
|
quote: Originally posted by sunitagoswami Madhivanan,Just out of curiosity .....Sunita
No problem. If you use front end application to show the data, use it to number themMadhivananFailing to plan is Planning to fail |
 |
|
|
|