How can I (both) create a row and accessing that row in the same 'Stored Procedure'?
Posted
by Richard77
on Stack Overflow
See other posts from Stack Overflow
or by Richard77
Published on 2010-04-22T10:48:37Z
Indexed on
2010/04/22
10:53 UTC
Read the original article
Hit count: 229
sql-server-2008
Hello,
I'd like to get the value of the id column for an object just after I've created it. But I don't want to run another query for that. My book for beginner (SQL Server 2008 for Dummies) says that there are 2 tables (inserted and deleted) that hold the last row(s) that have been inserted, updated, or deleted.
Unfortunately, only Triggers (says the book) can access those tables. But, if I use triggers, they will go off each time I "insert" a row even when I don't need them that functionality.
Can I obtain the same effect with a Store Procedure (without having to run a separate query?)
This is what I'm trying to do
CREATE PROCEDURE myProcedure
DECLARE @OrganizationName
@ColumnID OUTPUT
AS
INSERT INTO Organization (OrganizationName)
VALUES (@OrganizationName)
SET @ColumnID = (// Please, I need Help here ...)
Thanks for helping
© Stack Overflow or respective owner