View Single Post
  #1 (permalink)  
Old 10-10-2008, 10:09 AM
JaedenRuiner's Avatar
JaedenRuiner JaedenRuiner is offline
VB.NET Forum Master
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Aug 2007
Age: 30
Posts: 310
Reputation: 67
JaedenRuiner probably authored a book by nowJaedenRuiner probably authored a book by nowJaedenRuiner probably authored a book by now
Default Stored Procedures Return Value

Stored procedures seem to have a return value on the VB side of things, but I wasn't to sure on the SQL Server side of things, as well I've seen help on how ExecuteScalar on a Stored procedure can return a single value (like the ID of the item just entered or whatnot.

How would I write the Stored procedure to do that? Can I just add a Return {X} at the end of the procedure or is it more complicated than that?

here's the proc:
Code:
ALTER PROCEDURE [dbo].[InsertEmail] 
	-- Add the parameters for the stored procedure here
	@custid nvarchar(6) = '', 
	@qty int = 0
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	DECLARE @Num int
	DECLARE @ID nvarchar(10)
	SET @Num = dbo.NextEmailID(@custid) 
	SET @ID = ((right(@custid,(3))+'-')+right('0000'+CONVERT([nvarchar](5),@Num,(0)),(5)))
	INSERT INTO [dbo].[tbl_Email] (Num, Customer, Email_ID, ExpQty) VALUES (@Num, @custid, @ID, @qty)
END
The Value in that proc I would like returned is @ID, but would that mean I should convert it to a function instead of a procedure?

Thanks
__________________
Jaeden "Sifo Dyas" al'Raec Ruiner
http://www.wayoftheleaf.net/
Reply With Quote