|
zafarthesultan
Starting Member
16 Posts |
Posted - 2010-01-26 : 00:45:02
|
| Can anyone help me to get the result please?IF OBJECT_ID('TempDB..#mastertable','U') IS NOT NULLDROP TABLE #mastertable;CREATE TABLE #mastertable(ID int,Introducer int,MemberName nvarchar(50),LeftMember int,RightMember int,BusinessValue int)INSERT INTO #mastertable(ID,Introducer,MemberName,LeftMember,RightMember,BusinessValue)SELECT 1,10, 'A', 2,3, 50 UNION ALLSELECT 2,10, 'B', 4,5, 50 UNION ALLSELECT 3,1, 'C', 6,7, 50 UNION ALLSELECT 4,1, 'D', NULL,NULL, 50 UNION ALLSELECT 5,2, 'E', NULL,NULL, 50 UNION ALLSELECT 6,3, 'F', NULL,NULL, 50 UNION ALLSELECT 7,4, 'G', NULL,NULL, 50;IF OBJECT_ID('TempDB..#valuetable','U') IS NOT NULLDROP TABLE #valuetable;CREATE TABLE #valuetable(ID int,valuepoints int)INSERT INTO #valuetable(ID,valuepoints)SELECT 1,100 UNION ALLSELECT 2,100 UNION ALLSELECT 3,100 UNION ALLSELECT 4,0 UNION ALLSELECT 5,0 UNION ALLSELECT 6,0 UNION ALLSELECT 7,0;1 has 2 to his left and 3 to his right. 2's value points are 100 and 3's value points are 100. So the points of 1 will be calculated as follows:1's left member in the mastertable is 2 so 1's leftpoints will be points of 2 in the valuetable i.e. 100. Similarly 1's right member in the master table is 3 so rightpoints of 1 will be points of 3 in the valuetable i.e. 100The output required:id leftpoints rightpoints1 100 1002 0 03 0 04 0 05 0 06 0 07 0 0 |
|