Sql server 存储过程(SQL Server-2008)中的下两个查询中未插入数据

Sql server 存储过程(SQL Server-2008)中的下两个查询中未插入数据,sql-server,stored-procedures,Sql Server,Stored Procedures,大家好,我有一个关于sql server查询的问题 我创建了一个过程,在该过程中,我在一个表名tbasbalance中为一个单人链插入数据,但我的查询没有完全执行它只插入了一半的数据,而一半的数据没有插入这里是我的sp ALTER PROCEDURE [dbo].[AS_ActivateNewRetailerPortal] -- Add the parameters for the stored procedure here @UserID bigint, @actMobileNo nvarch

大家好,我有一个关于sql server查询的问题

我创建了一个过程,在该过程中,我在一个表名tbasbalance中为一个单人链插入数据,但我的查询没有完全执行它只插入了一半的数据,而一半的数据没有插入这里是我的sp

ALTER PROCEDURE [dbo].[AS_ActivateNewRetailerPortal]
-- Add the parameters for the stored procedure here
@UserID bigint,
@actMobileNo nvarchar(15)

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @returnvalue int
DECLARE @uQID bigint
DECLARE @xUserid bigint
DECLARE @uType varchar(2)
DECLARE @uBalance float
DECLARE @paidAmount float
DECLARE @DistAmount float
DECLARE @FrAmount float
DECLARE @uRole nvarchar(15)
DECLARE @type varchar(10)
DECLARE @Distid bigint
DECLARE @Frid bigint

SET @returnvalue=0

SELECT @uRole=UserRole FROM tbAsUserMaster WHERE UserID=@UserID
SELECT @Distid=UserOwner FROM tbAsUserMaster WHERE UserID=@UserID
SELECT @Frid=UserOwner FROM tbAsUserMaster WHERE UserID=@Distid
IF(@uRole='Dealer')
BEGIN
SELECT @xUserid=UserID FROM tbAsUserMaster WHERE rtrim(UserPMobileNo)=rtrim(@actMobileNo)
IF(@xUserid is not null )
BEGIN
if not exists(select * from tbASSMSActivation where userid=@UserID and [Status] =1)
begin
SET @returnvalue=39
RETURN @returnvalue
end
select @paidAmount =kitamt from tbASSMSActivation where userid=@UserID and [Status] =1
select @DistAmount =distAmt from tbASSMSActivation where userid=@UserID and [Status] =1
select @FrAmount =FrAmt from tbASSMSActivation where userid=@UserID and [Status] =1
if(@paidAmount is null or @paidAmount='')
BEGIN
set @paidAmount =0
END

SELECT @uBalance=dbo.As_getBalance(@UserID)
IF( @uBalance<@paidAmount)
BEGIN
SET @returnvalue=31
RETURN @returnvalue
END
ELSE
BEGIN
--Withdraw New Retaler charges
--DECLARE @uPWD nvarchar(36)
--SELECT @uPWD=newid()

INSERT INTO tbAsBalance (UserID,uAmount,uSaleDate,uPaymentBY,uAmountMode,uPrevBalance)
VALUES (@UserID,CAST('-' + CAST(@paidAmount AS NVARCHAR) as bigint),GETDATE(),@xUserid,'SMS',dbo.As_getBalance(@UserID))

UPDATE tbAsUserMaster SET UserStatus=1 WHERE UserID=@xUserid
if(@DistAmount >0)
begin
INSERT INTO tbAsBalance (UserID,uAmount,uSaleDate,uPaymentBY,uAmountMode,uPrevBalance)
VALUES (@Distid,@DistAmount,GETDATE(),@UserID,'SMS',dbo.As_getBalance(@Distid))
end

if(@FrAmount >0)
begin
INSERT INTO tbAsBalance (UserID,uAmount,uSaleDate,uPaymentBY,uAmountMode,uPrevBalance)
VALUES (@Frid,@FrAmount,GETDATE(),@UserID,'SMS',dbo.As_getBalance(@Frid))
end

SET @returnvalue=1
END
END
ELSE
BEGIN
SET @returnvalue=29
END
END
ELSE
BEGIN
SET @returnvalue=200
END
RETURN @returnvalue
END

SET ANSI_NULLS OFF
现在,在第一个insert查询之后,下两个insert命令不起作用。没有数据插入使用这些命令。现在我需要,如果任何插入命令将无法工作,那么插入数据的命令也将取消。
有可能吗?或者有其他解决方案吗?

可能是因为相同的用户ID。如果UserID是唯一的,则不允许输入新记录。否检查代码UserID是否是基于it用户id的代码UserID我正在获取分销商id和特许经营id,并且我正在该@himanshu中插入从过程返回的数据-1、29、31,39 200?当整个过程完成时,它在结尾返回0@deanset设置探查器跟踪以捕获SP:StatementStarted和SP:statementscompleted,以确保过程内部发生了什么。