Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server-2008
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 8-Aug-12 4:52am
Edited 8-Aug-12 4:58am
v4
Comments
Wes Aday at 8-Aug-12 10:21am
   
http://www.sqlteam.com/article/stored-procedures-returning-data
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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!
Smile | :)
  Permalink  
v2
Comments
tejaramesh97 at 9-Aug-12 4:40am
   
thanx
aarti meswania at 9-Aug-12 4:47am
   
welcome :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Because you are not returning or selecting user id in the above procedure.
 
try
return @UserId 
 
at the end
 
or
 
select @UserId.
  Permalink  

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

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 8 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100