Categories

.NET (1) CSS (5) OOP (1) PHP (2) SQL (5) SQL Server (8) TSQL (1)

Wednesday, July 18, 2012

OUTPUT Clause in SQL SERVER 2008 - Update


 --Decalring temp table
  DECLARE @OUTPUTTABLE Table
  (
ID INT,
NAME VARCHAR(100),
OLDNAME VARCHAR(100),
PRICE Decimal(18,2),
OLDPRICE Decimal(18,2) 
  ); 
  
  UPDATE  dbo.SourceTable
  SET Name='TestUpdate',
 Price=64
  OUTPUT
 inserted.ID,
 inserted.Name,
 deleted.Name,
 inserted.Price,
 deleted.Price
  INTO @OUTPUTTABLE(ID,NAME,OLDNAME,PRICE,OLDPRICE)
  WHERE ID=3
  
  
  SELECT *  FROM [EVSSQL].[dbo].[SourceTable]
  
  SELECT *  FROM @OUTPUTTABLE

No comments:

Post a Comment