I asked the same question in my previous post but could not explain my requirement properly and hence did not get the desired result. I want to do something like this:
There are 14 levels in total.Each level can have any number of users. Thank you for the answers provided in the previous post, I tried them but none gave me the desired result. Please give me an idea how to start with this. As of now my stored procedure looks like this:
ALTER PROCEDURE [dbo].[UserTransac]
@SponsorId varchar(20),
@UserId varchar(20),
@SponsorName varchar(50),
@Level int=1
AS
BEGIN
if not exists(select User_Id from UserTransaction)
insert into UserTransaction(Sponsor_Id,User_Id,Level_No,Sponsor_Name) values(@SponsorId,@UserId,@Level,@SponsorName)
else
insert into UserTransaction(Sponsor_Id,User_Id,Level_No,Sponsor_Name) values(@SponsorId,@UserId,@Level,@SponsorName)
insert into UserTransaction(Sponsor_Id,User_Id,Level_No,Sponsor_Name) values(@SponsorId,@UserId,@Level+1,@SponsorName)
END
The insert statement goes on till level 14.
After executing the stored procedure my table would look something like this:
Any useful links or answers where I can get an idea how to go about with this would help. Thank you.
UPDATE:
Consider the last two records 11 and 12. For both the records sponsor Id is coming as RL9115. I want all the levelsto be displayed -ie something like this:
Hope this is somewhat clear to understand what I want to do