October 21, 2010 at 2:58 pm
Hi folks . . . hopefully this is just a quick question.
Was just reading BOL regarding the OUTPUT clause. I'd like to take a column value generated from an INSERT and pass it to a variable.
Does the variable have to be a TABLE variable, or is there a way to pass it into a common variable such as INT or NVARCHAR (or, in my particular situation, a UNIQUEIDENTIFIER)?
Thanks!
+--------------------------------------------------------------------------------------+
Check out my blog at https://pianorayk.wordpress.com/
October 21, 2010 at 3:30 pm
You can either use a table (table variable, temporary table, permanent table) (results to into it), or not (results to client). But not to a "regular" variable. See the BOL OUTPUT Clause entry.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
October 21, 2010 at 3:35 pm
Okay, that's what I figured.
I ended up just creating a simple SELECT statement for the column immediately following the INSERT. I'm just writing a quick 'n dirty, and it's insignificant enough that having to create a TABLE variable for it would be unnecessary overkill.
Thanks!
+--------------------------------------------------------------------------------------+
Check out my blog at https://pianorayk.wordpress.com/
October 21, 2010 at 3:59 pm
Ray K (10/21/2010)
Okay, that's what I figured.I ended up just creating a simple SELECT statement for the column immediately following the INSERT. I'm just writing a quick 'n dirty, and it's insignificant enough that having to create a TABLE variable for it would be unnecessary overkill.
Thanks!
Say what? Overkill???
DECLARE @test-2 TABLE (Col1 uniqueidentifier);
INSERT INTO .....
OUTPUT i.MyUniqueIdentifierColumn INTO @test-2
....
SELECT * FROM @test-2;
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
October 21, 2010 at 4:11 pm
WayneS (10/21/2010)
Say what? Overkill???
Edit: my original reply was a bit too flippant -- didn't want anyone to take it the wrong way!
Maybe "overkill" wasn't the right word -- rather, what I was doing wasn't terribly big, and I didn't think it necessitated the need to create a table variable.
+--------------------------------------------------------------------------------------+
Check out my blog at https://pianorayk.wordpress.com/
October 22, 2010 at 8:20 am
see Examples at below link:
http://mssqlsolutions.blogspot.com/2008/08/how-to-use-output-clause.html
Tariq
master your setup, master yourself.
http://mssqlsolutions.blogspot.com
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply