Hi all,
In sql server What is the use of Output keyword ? Explain me with an example?
Thanks,
M.Maheswar
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Datta KharadPosted Nov 18, 2011, 7:55 AM
OUTPUT parameters when it comes to "named parameters" or "ordinal parameters". In SQL Server this terminology this applies to the EXEC call and how you specify parameters there: not direction
Ordinal = position must match and datatype must be compatible
Named = assign the local value to the stored proc parameter name. Only datatype must be compatible
This is ordinal
declare @bob as int, @rich as char(20)
--OK
exec test @bob output, @rich output
GO
declare @bob as int, @rich as char(20)
--Fail
exec test @bob output, @rich output
This is named
declare @bob as int, @rich as char(20)
--OK
exec test
@ID = @bob output,
@mark = @rich output
GO
declare @bob as int, @rich as char(20)
--OK
exec test
@mark = @rich output,
@ID = @bob output
AartiPosted Nov 18, 2011, 7:18 AM
After performing data entry on a table or a view, to output the results in a separate table, you can use the OUTPUT operator. The formula to follow is:
INSERT INTO TableName
OUTPUT INSERTED.Columns
VALUES(Value_1, Value_2, Value_X)
Here is an example:
CREATE TABLE Videos
(
Title nvarchar(50),
Director nvarchar(50),
WideScreen bit,
Rating nchar(10),
YearReleased int
);
INSERT INTO Videos
OUTPUT inserted.*
VALUES(N'War of the Roses (The)', N'Dany de Vito', 0, N'R', 2001),
(N'Memoirs of a Geisha', N'Rob Marshall', 1, N'PG-13', 2006),
(N'Last Castle (The)', N'Rod Lurie', 1, N'', 2001),
(N'Sneakers', N'Phil Alden Robinson', 1, N'PG-13', 2003);
When this statement executes, if you are working in the Microsoft SQL Server Management Studio,
the lower part would display a list of the records that were added
Thanks.
Prabhu RajaPosted Oct 8, 2011, 7:12 AM
VulpesPosted Oct 7, 2011, 7:12 AM
http://msdn.microsoft.com/en-us/library/ms177564.aspx