Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rameshduraikannu
Starting Member
10 Posts |
Posted - 2009-11-30 : 06:21:08
|
| http://www.sqlservercentral.com/Forums/Attachment4582.aspxrameshduraikannu |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-11-30 : 06:40:46
|
| Sorry, can you post your question here as I and other will not want to open/save a document posted elsewhere.Thanks |
 |
|
|
rameshduraikannu
Starting Member
10 Posts |
Posted - 2009-11-30 : 07:01:12
|
quote: Originally posted by RickD Sorry, can you post your question here as I and other will not want to open/save a document posted elsewhere.Thanks
quote: hai to allI have two tables ('admin' and 'user'). These tablescontain among others fields as below.admin Location grade 1 240 2 270 1 300 Compare both and round to nearest to admin value(240)userLocation Grade value 1 246 1 273 2 301I would like a query that finds the grade (from the admintable) compares it to ' Grade value ' (from user) and returnsthe Grade value
rameshduraikannu |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-30 : 07:15:37
|
| What have you tried so far?MadhivananFailing to plan is Planning to fail |
 |
|
|
rameshduraikannu
Starting Member
10 Posts |
Posted - 2009-11-30 : 08:06:16
|
quote: Originally posted by madhivanan What have you tried so far?MadhivananFailing to plan is Planning to fail
quote: Select * from (Select u.*, a.grade as nearest, Row_number()OVER(PArtition by grade_value order by ABS(grade_value - grade)) as row_num from #admin a CROSS JOIN #user u) twhere row_num = 1
rameshduraikannu |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-11-30 : 09:44:34
|
| so what should be output out of your sample data? |
 |
|
|
|
|
|