How can i increment the counter? <p>At the registration time i wanted if side is left then my left count will increment and side is Right then my right is increment and both side is filled then their sponcor will increment... How can i do this????</p> <p>HERE i wanted to increment the my counter but it is not working propperly always counter show me null...., please tell me where m wrong.???</p> <pre><code>DECLARE @regid int SET @regid=@@IDENTITY DECLARE @RegistrationCode varchar(100) DECLARE registrationcodeCursor CURSOR FOR SELECT [dbo].[RegistrationCode] ( 'P4U',@fname,@mname,@lname,'000',@regid,'34',@dob ) OPEN registrationcodeCursor FETCH FROM registrationcodeCursor INTO @RegistrationCode CLOSE registrationcodeCursor DEALLOCATE registrationcodeCursor UPDATE Registration_Master SET regCode=@RegistrationCode WHERE registrationid=@regid DECLARE @regid1 int SET @regid1=@@IDENTITY DECLARE @usernm varchar(50) DECLARE usernameCursor CURSOR FOR SELECT [dbo].[fullusername] ( @fname,' ',@mname,' ',@lname ) OPEN usernameCursor FETCH FROM usernameCursor INTO @usernm CLOSE usernameCursor DEALLOCATE usernameCursor UPDATE Registration_Master SET username=@usernm WHERE registrationid=@regid1 --Pair Matching SET @count_mem=0 WHILE(@sponcorid!=NULL) BEGIN IF(@regCode !=NULL) BEGIN DECLARE @countl int IF(@side ='LEFT') BEGIN UPDATE Registration_Master SET @count_mem=@count_mem+1 WHERE regCode=@regCode AND side='LEFT' AND count_mem=@count_mem END DECLARE @countr int IF(@side='RIGHT') BEGIN UPDATE Registration_Master SET @count_mem=@count_mem+1 WHERE regCode=@regCode AND side='RIGHT' AND count_mem=@count_mem END IF(@countl=@countr) BEGIN UPDATE Registration_Master SET @count_mem=@count_mem+1 WHERE regCode=@regCode IF(@regCode!=NULL) BEGIN UPDATE Registration_Master SET @count_mem=@count_mem+1 WHERE sponcorid=@sponcorid AND count_mem=@count_mem END END END END SELECT registrationid, regCode, fname,mname,lname,username, p_password,question,answer, person_address, gender, sponcorid, dob,productname, payment, sponcorname, side, mobile, bankname, baccno, bankbranch, PAN, IFSC_code, email_id, member_status, count_mem,smart_pin,createddate, is_activate FROM Registration_Master WHERE registrationid=@@IDENTITY </code></pre>