MS SQL Server
  Home arrow MS SQL Server arrow Page 3 - Wonders of the OUTPUT Clause in SQL Server...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MS SQL SERVER

Wonders of the OUTPUT Clause in SQL Server 2005
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 9
    2006-05-08

    Table of Contents:
  • Wonders of the OUTPUT Clause in SQL Server 2005
  • OUTPUT clause with single INSERT statement
  • OUTPUT clause with multiple INSERT statements
  • OUTPUT clause with single DELETE statement
  • OUTPUT clause with single UPDATE statement

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Wonders of the OUTPUT Clause in SQL Server 2005 - OUTPUT clause with multiple INSERT statements


    (Page 3 of 5 )

    The previous section concentrated only on single INSERT statements.  Let us now examine multiple INSERT statements employing the OUTPUT clause.

    Let’s go through the script first.

    Use Northwind
     
    Declare @ins as table(InsRegionID int,InsRegionDescription nchar(50))
     
    Insert Region(RegionID,RegionDescription)
    Output inserted.Regionid,inserted.RegionDescription into @ins
    values(7,'NorthWest')
     
    Insert Region(RegionID,RegionDescription)
    Output inserted.Regionid,inserted.RegionDescription into @ins
    values(8,'SouthEast')
     
    Insert Region(RegionID,RegionDescription)
    Output inserted.Regionid,inserted.RegionDescription into @ins
    values(9,'NorthEast')
     
     
    Insert Region
    Output inserted.Regionid,inserted.RegionDescription into @ins
    values(10,'SouthWest')
     
    --Display Newly Inserted Value will be displayed
    Select * from @ins
     
    --Displays all values along with newly Inserted values will be displayed
     
    Select * from Region

    The above example is similar to the previous one except for the difference in the number of INSERT statements. In the previous example, we inserted a single row of information, but here we are inserting more than one row. We can specify as many INSERT statements as we want. Every INSERT statement adds a new row to the same virtual table “@ins.”

    Finally, we execute the SELECT statement on the virtual table “@ins,” which directly retrieves all the values cached and displays them to the screen.

    More MS SQL Server Articles
    More By Jagadish Chaterjee


       · Hello guys! This is an introductory to OUTPUT clause in SQL Server 2005. Try it...
       · Thanks
       · Hi, Nice article, but I was wondering if you have any hints on how to use this...
     

    MS SQL SERVER ARTICLES

    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services
    - Building a Multi-table Report with SQL 2005 ...
    - A Secure Way of Building Connection Strings
    - Transferring a Database Using the SSIS Desig...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT