Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

How to know the columns name which effected by from update statement

$
0
0


how to know the columns which are updated  COLUMNS_UPDATED()  

how to use this its looks difficult get exact the name please help 


DECLARE @maxPosi AS INT
DECLARE @realUpdate AS INT
DECLARE @posi AS INT

SET @maxPosi = LEN(COLUMNS_UPDATED())
SET @realUpdate = 0
SET @posi = 1

WHILE (@posi <= @maxPosi)
BEGIN
IF @posi-1 = 0
BEGIN
SET @realUpdate = @realUpdate + CAST(SUBSTRING(COLUMNS_UPDATED(),@posi,1) AS INT)
END
ELSE
BEGIN
IF SUBSTRING(COLUMNS_UPDATED(),@posi,1) > 0
BEGIN
SET @realUpdate = @realUpdate + CAST(SUBSTRING(COLUMNS_UPDATED(),@posi,1) * POWER(2,8*(@posi-1)) AS INT)
END
END
SET @posi = @posi +1
END

SELECT CAST(POWER(2,colorder-1) as int), @realupdate , name FROM syscolumns WHERE id = ANY (SELECT id FROM sysobjects WHERE Name = 'MyTable') AND POWER(2,colorder-1) & @realUpdate > 0 


Ranjith@Learner @Microsoft products


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>