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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Lag values to be populated

Author  Topic 

bhaasjoshi
Starting Member

17 Posts

Posted - 2010-06-18 : 02:00:17
Hi friends,

I have the following table,
ID Grade Var1
1 4
1 3
1 2
1 1 83
_______________________
2 4
2 3 15
2 2 8
2 1
_______________________
3 4
3 3 8
3 2
3 1
________________________
4 4 24
4 3
4 2 10
4 1

I need to populate some values based on the following logic,
(1) For ID 1, Grade 1 is the minimum grade so no values for VAR1 in higher grades(2,3,4) can be NULL (it is already like that).
(2) For ID 2, Grade 1 needs values in VAR1 from the immediate higher grade i.e. Grade 2. Grade 4 can be null.
(3) For ID 3, The values from Grade 3 need to be populated in Grades 2 and 1 (lower grades which are null).
(4) For ID 4, The value of Grade 3 should be the value of the immediate higher grade i.e. grade 4, and similarly the value of Grade 1 should be the value of the immediate higher grade i.e. grade 2.

The final expected output is as following,
ID Grade Var1
1 4
1 3
1 2
1 1 83
________________________
2 4
2 3 15
2 2 8
2 1 8
_______________________
3 4
3 3 8
3 2 8
3 1 8
_________________________
4 4 24
4 3 24
4 2 10
4 1 10

Please help, the application which I am using is called Integrated Review and has its own limitations, but if I could atleast get an easy logic to follow it would be great.

Thanks,
BJ
   

- Advertisement -