帮助我编写存储过程 [英] Help me on Write Stored Procedure

查看:114
本文介绍了帮助我编写存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Create PROCEDURE [dbo].[Sp_TaccountdetailsB] 
@i int,
@UserId int,
@amount decimal(18,2),
@duserid int,
@caccountnumber varchar(50)
AS
BEGIN
	
	if @i=0
	BEGIN
	select AccountNumber,AccountType,Amount from tblT_AccountDetailsB where AccountDetailsId=( select MAX(AccountDetailsId) from tblT_AccountDetailsB where UserId = @UserId)
	END
	ELSE IF @i=1
	BEGIN
	select AccountNumber,Amount,Credited,Debited from tblT_AccountDetailsB where AccountDetailsId=(select  MAX(AccountDetailsId) from tblT_AccountDetailsB where UserId=@UserId)
	END
	ELSE IF @i=2
	BEGIN
	select AccountNumber,Amount,Credited,Debited from tblT_AccountDetailsB where UserId=@UserId
	END
	ELSE IF @i=3
	BEGIN
	Declare @cAccountType varchar(50)
	Declare @dAccountType varchar(50)
	Declare @cBranchId int
	Declare @dBranchId int
	Declare @cuserid int
    Declare @daccountnumber varchar(50)
    declare @damount decimal(18,2)
    declare @camount decimal(18,2)
	set @daccountnumber=(select AccountNumber from tblT_AccountDetailsB where UserId=@duserid)
	set @cuserid=(select distinct UserId from tblT_AccountDetailsB where AccountNumber=@caccountnumber)
	set @cAccountType=(select Distinct AccountType from tblT_AccountDetailsB where UserId=@cuserid)
	set @dAccountType=(select Distinct AccountType from tblT_AccountDetailsB where UserId=@duserid)
	set @cBranchId=(select Distinct BranchId from tblT_AccountDetailsB where UserId=@cuserid)
	set @dBranchId=(select Distinct BranchId from tblT_AccountDetailsB where UserId=@UserId)
	set @damount=((select Amount from tblT_AccountDetailsB where UserId=@duserid)-@amount)
	set @camount=((select Amount from tblT_AccountDetailsB where UserId=@cuserid)+@amount)
	insert into tblT_AccountDetailsB (AccountNumber,BranchId,AccountType,Amount,UserId,Debited) values (@daccountnumber,@dBranchId,@dAccountType,@damount,@duserid,@amount)
	insert into tblT_AccountDetailsB (AccountNumber,BranchId,AccountType,Amount,UserId,Credited) values (@caccountnumber,@cBranchId,@cAccountType,@camount,@cuserid,@amount)

	end



此存储过程已执行,但未返回UserId
请帮助我如何编写存储过程如果我想重新调整用户ID,请...



this stored procedure is executed but not returns the UserId
please help me how to write Stored Procedure If i want to retun UserId Please...

推荐答案

在存储过程结束时记下此"return"语句

write down this ''return'' statement when store-procedure ends

insert into tblT_AccountDetailsB (AccountNumber,BranchId,AccountType,Amount,UserId,Credited) values (@caccountnumber,@cBranchId,@cAccountType,@camount,@cuserid,@amount)

--here you can return userid
return @userid

end


祝您编码愉快!
:)


Happy Coding!
:)


因为您没有在上述过程中返回或选择用户ID.

试试
Because you are not returning or selecting user id in the above procedure.

try
return @UserId 



最后





at the end

or

select @UserId.


这篇关于帮助我编写存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆