| Author |
Topic |
|
cgfl_dubai
Starting Member
3 Posts |
Posted - 2006-06-21 : 03:13:43
|
| hi,HAve to run this as a single quey in sql server 2000.I have got a query which has to return the previous row data to the current row if its value is null ex: Prod Id. Name Qty 1 AAA 102 BBB Null3 CCC Null4 DDD 205 EEE 20 So in this case the result should be Prod Id. Name Qty 1 AAA 102 BBB 103 CCC 104 DDD 205 EEE 20 Thanx in advance ! Cheers,Pari. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-06-21 : 03:18:51
|
[code]select ProdID, Name, coalesce(Qty, (select top 1 Qty from table x where Qty is not null and x.ProdID < t.ProdID order by x.ProdID desc))from table t[/code] KH |
 |
|
|
cgfl_dubai
Starting Member
3 Posts |
Posted - 2006-06-21 : 04:14:54
|
| Hi many thanks, it works at its best provided the id should be unique !!! |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-06-21 : 04:27:49
|
quote: Originally posted by cgfl_dubai Hi many thanks, it works at its best provided the id should be unique !!!
Is the Prod ID unique in your case ? KH |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-06-21 : 04:49:47
|
| Why do you want to do this?Do you use any front end application to show the data?MadhivananFailing to plan is Planning to fail |
 |
|
|
cgfl_dubai
Starting Member
3 Posts |
Posted - 2006-06-21 : 05:28:17
|
| I tried to test in the sample one, in that the prod id was not uniqueafter changing the test data to unique it worked ! |
 |
|
|
suneil23
Starting Member
4 Posts |
Posted - 2006-06-25 : 02:23:39
|
| hello guys i couldn understand wat ur trying to say..pls lemme know wat x and t stand for in the query written above... |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-06-25 : 03:02:08
|
quote: Originally posted by suneil23 hello guys i couldn understand wat ur trying to say..pls lemme know wat x and t stand for in the query written above...
x and t are table alias. KH |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|