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 2005 Forums
 Transact-SQL (2005)
 capture value in stored procedure

Author  Topic 

albertkohl
Aged Yak Warrior

740 Posts

Posted - 2007-11-14 : 01:14:27
Okay, so i have a stored procedure that inserts some values that VB.net passes it. thing is, i would like to capture the CountID field that is auto-populated by SQL with a Unique Value.

can anyone point me in the right direction to
a) get Sql to output the countid of the record it inserted
and
b) allow vb.net to capture that value


USE [Test]
GO

alter PROCEDURE [dbo].[save_order_1]
(@records int,@tableused nvarchar(50),@date datetime,@username varchar(50)) AS
INSERT INTO dbo.orders (records,tableused,[date],username)
VALUES
(@parameters,@records,@tableused,@date,@username)

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2007-11-14 : 01:29:15
I am assuming the CountID is a identity field.

add this to the end of the procedure

return Scope_Identity()


You can then capture this with .net by adding a Output Parameter to the sql command object
Go to Top of Page
   

- Advertisement -