Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

The maximum recursion 100 has been exhausted before statement completion

$
0
0

hi  following is the my table , data and stored procedure but when we execute my stored procedure as follows

exec CountDownlineNode 'LDS'

it does not show any record and it take infinite time in execution but when we use OPTION( MAXRECURSION 100) in the place of  OPTION( MAXRECURSION 0) it give the following error

 

Msg 530, Level 16, State 1, Procedure CountDownlineNode, Line 7 The statement terminated. The maximum recursion 100 has been exhausted before statement completion.

Warning: Null value is eliminated by an aggregate or other SET operation.

 so how can resolve these issues  please any can suggest us as early as possible or give the solution

 

thanks

following is the my table , data and stored procedure

/****** Object:  Table [dbo].[Table_DownLineList]   Script Date: 11/17/2013 21:22:04 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[Table_DownLineList](

               [Sr_No] [int] IDENTITY(1,1) NOT NULL,

               [Member_ID] [nvarchar](50) NULL,

               [Member_Name] [nvarchar](50) NULL,

               [Joining_Date] [nvarchar](50) NULL,

               [Upline_ID] [nvarchar](50) NULL,

               [Upline_Name] [nvarchar](50) NULL,

               [City] [nvarchar](50) NULL,

               [Placement_Leg] [nvarchar](50) NULL

) ON [PRIMARY]

GO

SET IDENTITY_INSERT [dbo].[Table_DownLineList] ON

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (1, N'LDS', N'LDS', N'11-11-2013', NULL, NULL, NULL, NULL)

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (2, N'LDS1', N'LDS', N'11-10-2013', N'LDS', N'LDS Raj', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (3, N'LDS2', N'LDS', N'11-10-2013', N'LDS', N'LDS Raj', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (4, N'SUNIL', N'SUNIL DUTT', N'11-10-2013', N'LDS1', N'LDS', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (5, N'SUNIL01', N'SUNIL DUTT', N'11-10-2013', N'SUNIL', N'SUNIL DUTT', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (6, N'SUNIL2', N'SUNIL DUTT', N'11-10-2013', N'SUNIL', N'SUNIL DUTT', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (7, N'RAJKISHOR', N'RAJKISHOR SHARMA', N'11-10-2013', N'SUNIL01', N'SUNIL DUTT', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (8, N'RAJKISHOR01', N'RAJKISHOR SHARMA', N'11-10-2013', N'RAJKISHOR', N'RAJKISHOR SHARMA', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (11, N'RAJA1', N'HARISH CHANDR', N'11-10-2013', N'RAJA', N'HARISH CHANDR', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (14, N'SURJEET1', N'SURJEET SINGH', N'11-10-2013', N'SURJEET', N'SURJEET SINGH', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (15, N'SURJEET2', N'SURJEET SINGH', N'11-10-2013', N'SURJEET', N'SURJEET SINGH', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (16, N'RAMASARE', N'RAMASARE', N'11-11-2013', N'SURJEET1', N'SURJEET SINGH', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (18, N'JITENDR', N'JITENDR KUMAR', N'11-11-2013', N'PRADEEP', N'PRADEEP KUMAR', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (19, N'JITENDR1', N'JITENDR KUMAR', N'11-11-2013', N'JITENDR', N'JITENDR KUMAR', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (21, N'RAJKUMARI', N'RAJKUMARI', N'11-11-2013', N'DHARAMVEER', N'DHARMVEER', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (23, N'RAMVEER', N'RAMVEER', N'11-11-2013', N'NEERAJA', N'NEERJA', N'DIBIYAPUR', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (26, N'SATEESH', N'SATISH KUMAR', N'11-11-2013', N'HARISWAROOP', N'HARISWAROOP', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (28, N'RAGHVENDR', N'RAGHVENDR SINGH', N'11-11-2013', N'GEETA', N'GEETA DEVI', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (30, N'BALVEER', N'BALVEER SINGH', N'11-11-2013', N'RAJENDR', N'RAJENDR SINGH', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (31, N'LAYAK', N'LAYAK SINGH', N'11-11-2013', N'BALVEER', N'BALVEER SINGH', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (32, N'MULAYAM', N'MULAYAM SINGH', N'11-11-2013', N'LAYAK', N'LAYAK SINGH', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (33, N'RAJKUMAR', N'RAJKUMAR', N'11-11-2013', N'LAYAK', N'LAYAK SINGH', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (34, N'MOHAN', N'', N'11-11-2013', N'RAJKUMAR', N'RAJKUMAR', N'', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (38, N'ANSAR', N'ANSAR KHAN', N'11-11-2013', N'RAJA1', N'HARISH CHANDR', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (40, N'ANSAR2', N'ANSAR KHAN', N'11-11-2013', N'ANSAR', N'ANSAR KHAN', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (41, N'NASURUDDIN', N'MU. NASURUDDIN', N'11-11-2013', N'ANSAR2', N'ANSAR KHAN', N'MAINPURI', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (42, N'ANIS', N'ANIS KHAN', N'11-11-2013', N'NASURUDDIN', N'MU. NASURUDDIN', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (44, N'BASEEM', N'MU. BASEEM', N'11-11-2013', N'SURJEET01', N'SURJEET KUMAR', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (45, N'PREMPAL', N'PREMPALSINGH', N'11-11-2013', N'BASEEM', N'MU. BASEEM', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (47, N'GK1', N'GIRJESH KUMAR', N'11-11-2013', N'GK', N'GIRJESH KUMAR', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (49, N'AMLESH', N'AMALESH KUMAR', N'11-12-2013', N'RAJKISHOR02', N'RAJKISHOR SHARMA', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (50, N'RAMESH', N'RAMESH CHANDRA', N'11-12-2013', N'AMLESH', N'AMALESH KUMAR', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (54, N'GOVIND2', N'GOVIND SHAKYA', N'11-12-2013', N'GOVIND', N'GOVIND SHAKYA', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (55, N'DINESH', N'DINESH KUMAR', N'11-12-2013', N'GOVIND1', N'GOVIND SHAKYA', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (63, N'MANOJ1', N'MANOJ KUMAR', N'11-12-2013', N'MANOJ', N'MANOJ KUMAR', N'FIROZABAD', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (64, N'SHITAL', N'SHITAL DEVI', N'11-12-2013', N'MANOJ', N'MANOJ KUMAR', N'FIROZABAD', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (9, N'RAJKISHOR02', N'RAJKISHOR SHARMA', N'11-10-2013', N'RAJKISHOR', N'RAJKISHOR SHARMA', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (10, N'RAJA', N'HARISH CHANDR', N'11-10-2013', N'rajkishor01', N'RAJKISHOR SHARMA', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (12, N'RAJA2', N'HARISH CHANDR', N'11-10-2013', N'RAJA', N'HARISH CHANDR', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (13, N'SURJEET', N'SURJEET SINGH', N'11-10-2013', N'RAJA2', N'HARISH CHANDR', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (17, N'PRADEEP', N'PRADEEP KUMAR', N'11-11-2013', N'RAMASARE', N'RAMASARE', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (20, N'DHARAMVEER', N'DHARMVEER', N'11-11-2013', N'JITENDR1', N'JITENDR KUMAR', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (22, N'NEERAJA', N'NEERJA', N'11-11-2013', N'RAJKUMARI', N'RAJKUMARI', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (24, N'BRAJKISHOR', N'BRAJKISHOR', N'11-11-2013', N'RAMVEER', N'RAMVEER', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (29, N'RAJENDR', N'RAJENDR SINGH', N'11-11-2013', N'RAGHVENDR', N'RAGHVENDR SINGH', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (35, N'MOHAN', N'MOHAN SINGH', N'11-11-2013', N'RAJKUMAR', N'RAJKUMAR', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (39, N'ANSAR1', N'ANSAR KHAN', N'11-11-2013', N'ANSAR', N'ANSAR KHAN', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (51, N'GOPESH', N'GOPESH KUMAR', N'11-12-2013', N'RAMESH', N'RAMESH CHANDRA', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (53, N'GOVIND1', N'GOVIND SHAKYA', N'11-12-2013', N'GOVIND', N'GOVIND SHAKYA', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (60, N'RAMVEER1', N'RAMVEER SINGH', N'11-12-2013', N'ROOPWATI', N'ROOPWATI', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (65, N'REKHA', N'REKHA KUMARI', N'11-12-2013', N'MANOJ1', N'MANOJ KUMAR', N'FIROZABAD', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (25, N'HARISWAROOP', N'HARISWAROOP', N'11-11-2013', N'SURJEET2', N'SURJEET SINGH', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (27, N'GEETA', N'GEETA DEVI', N'11-11-2013', N'SATEESH', N'SATISH KUMAR', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (37, N'SAILENDRA', N'SAILENDR KUMAR', N'11-11-2013', N'RAVI', N'RAVI YADAV', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (52, N'GOVIND', N'GOVIND SHAKYA', N'11-12-2013', N'GK1', N'GIRJESH KUMAR', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (58, N'RAVI1', N'RAVI KUMAR', N'11-12-2013', N'NITIN', N'NITIN KUMAR', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (36, N'RAVI', N'RAVI YADAV', N'11-11-2013', N'RAGHVENDR', N'RAGHVENDR SINGH', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (43, N'SURJEET01', N'SURJEET KUMAR', N'11-11-2013', N'ANIS', N'ANIS KHAN', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (46, N'GK', N'GIRJESH KUMAR', N'11-11-2013', N'ANSAR1', N'ANSAR KHAN', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (48, N'GK2', N'GIRJESH KUMAR', N'11-11-2013', N'GK', N'GIRJESH KUMAR', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (59, N'ROOPWATI', N'ROOPWATI', N'11-12-2013', N'RAVI1', N'RAVI KUMAR', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (56, N'REKHA', N'REKHA', N'11-12-2013', N'DINESH', N'DINESH KUMAR', N'ETAWAH', N'Left')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (57, N'NITIN', N'NITIN KUMAR', N'11-12-2013', N'DINESH', N'DINESH KUMAR', N'ETAWAH', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (61, N'KISHAN', N'KISHAN', N'11-12-2013', N'RAMVEER1', N'RAMVEER SINGH', N'NOIDA', N'Right')

INSERT [dbo].[Table_DownLineList] ([Sr_No], [Member_ID], [Member_Name], [Joining_Date], [Upline_ID], [Upline_Name], [City], [Placement_Leg]) VALUES (62, N'MANOJ', N'MANOJ KUMAR', N'11-12-2013', N'REKHA', N'REKHA', N'FIROZABAD', N'Left')

SET IDENTITY_INSERT [dbo].[Table_DownLineList] OFF

 

and following is the my stored procedure

 

/****** Object:  StoredProcedure [dbo].[CountDownlineNode]   Script Date: 11/17/2013 21:21:55 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE proc [dbo].[CountDownlineNode]

(

 @memberid nvarchar(50)

)

as

begin

;with cte as (

        select

             Member_Name,  Member_ID, Upline_ID, Placement_Leg,

               null lnode,

               null rnode

        from Table_DownLineList where Member_ID =@memberid    

        union all

        select

               t.Member_Name, t.Member_ID, t.Upline_ID, t.Placement_Leg,

               ISNULL(cte.lnode, CASE WHEN t.Placement_Leg = 'Left' THEN 1 ELSE 0 END) lnode,

               ISNULL(cte.rnode, CASE WHEN t.Placement_Leg  = 'Right' THEN 1 ELSE 0 END) rnode

        from Table_DownLineList t

        inner join cte

                on cte.Member_ID=t.Upline_ID

)

select

        @memberid Member_ID,

        SUM(lnode) LeftNodes,

        SUM(rnode) RightNodes

        from cte  OPTION( MAXRECURSION 0)

end

GO

 

 




Viewing all articles
Browse latest Browse all 23857

Trending Articles