We help IT Professionals succeed at work.

Return value from store procedure

Guys,

Does some one could help me with my store procedure.

I just want to return a number of my Itentity to my parameter..

I'm getting erro with my code below;
-------------------------------------------------------------------------------------------

ALTER procedure [dbo].[Client_Insert_out]
@name varchar(30),
@surname varchar(30),
@email varchar(40),
@Return_ID int out
as begin
   if (not exists(select * from client where client.name=@name))
   begin
     set @Return_ID =  insert into client values(@name,@surname,@email) select SCOPE_IDENTITY()
   end
end


---------------------

Thanks
Comment
Watch Question

Application Support Analyst
Commented:
if (not exists(select * from client where client.name=@name))
   begin
      insert into client values(@name,@surname,@email)
      set @Return_ID = @@IDENTITY
   end

Open in new window

Author

Commented:
Thanks man..

Itkamaraj, can I make another question.

Store procedure return only number ok.  Is it possible to return that number with out using Out parameter ?

Tks
CERTIFIED EXPERT

Commented:
Yes, use:

return @Return_ID

or

select @Return_ID

The first will come back as the return value and the second comes back as a recordset.

Author

Commented:
Thank you very much..

I just begining with Sp..:)
CERTIFIED EXPERT

Commented:
It's a long journey but worth it :)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.