Alter procedure ProcTestGet @temp_name varchar(50), @sum int AS Declare @Tmp_id As int Declare @total_sum As int Declare @sum1 As int select @Tmp_id = @@identity If @Tmp_id = 0 Begin set @total_sum =Null insert into TblTest(temp_name,sum,total_sum) VALUES(@temp_name,@sum,@total_sum) End else begin select @total_sum = total_sum from TblTest where temp_id = @@identity if @total_sum = NULL begin select @sum1= sum from TblTest where temp_id = @@identity declare @totalsum int set @totalsum = @sum1 + @sum insert into TblTest(temp_name,sum,total_sum) VALUES(@temp_name,@sum,@totalsum) end else begin select @total_sum = total_sum from TblTest where temp_id = @@identity declare @totalsum1 int set @totalsum1 = @total_sum + @sum insert into TblTest(temp_name,sum,total_sum) VALUES(@temp_name,@sum,@totalsum1) end select @@identity End
|