Click here to Skip to main content
15,891,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
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


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...
Posted
Updated 8-Aug-12 3:58am
v4
Comments
[no name] 8-Aug-12 10:21am    
http://www.sqlteam.com/article/stored-procedures-returning-data

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

try
SQL
return @UserId 


at the end

or

SQL
select @UserId.
 
Share this answer
 
write down this 'return' statement when store-procedure ends

SQL
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!
:)
 
Share this answer
 
v2
Comments
tejaramesh97 9-Aug-12 4:40am    
thanx
Aarti Meswania 9-Aug-12 4:47am    
welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900