Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 How to Exec Stored Procedure and return OUTPUT val

Author  Topic 

mgreen84
Yak Posting Veteran

94 Posts

Posted - 2014-05-23 : 10:02:40
in the below script I have changed function getnextclaimnumber() to be a store procedure in sql server 2012, that uses a sequence generator.

My question now is though how can I alter the script to execute that procedure, but also assign the return OUTPUT value to 'claim_id'


RESERVE_CLAIM_NUMBER_SQL_TEMPLATE = "SELECT getnextclaimnumber() as claim_id";



* would Exec getnextclaimnumber @NextCMSClaimNumber as Claim_ID work?

the function was some java that was creating a sequence gen. But basically I'm removing all there java code and php code from doing the bulk of the work on a Postgres DB. By moving everything over to SQL Server environment, and well this particular function they had in java is simply done SQL 2012 with Sequences. So I just built out a Sequence gen and called it in this store procedure, but I place the return value in a OUTPUT variable.




ALTER PROCEDURE [claims].[getnextclaimnumber]
@NextCMSClaimNumber VarChar(20) OUTPUT
AS
BEGIN
SET NOCOUNT ON


-- Calls next avaliable claim number in sequence --
SELECT @NextCMSClaimNumber = NEXT VALUE FOR claims.ClaimNumber


-- Appends '0' to claim number --
Select '0'+ @NextCMSClaimNumber

End

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2014-05-23 : 10:18:30
Answered here (dupe post)
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=194362

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -