I am aware of COLUMNS_UPDATED
, well I need some quick shortcut (if anyone has made, I am already making one, but if anyone can save my time, I will appriciate i
I transformed the accepted answer to get list of column names separated by comma (according to author's recommendation). Output - "Columns_Updated" as 'Column1,Column2,Column5'
-- get names of updated columns
DECLARE @idTable INT
declare @ColumnName nvarchar(300)
declare @ColId int
SELECT @idTable = T.id
FROM sysobjects P JOIN sysobjects T ON P.parent_obj = T.id
WHERE P.id = @@procid
DECLARE @changedProperties nvarchar(max) = ''
DECLARE @Columns_Updated VARCHAR(2000) = ''
DECLARE @maxByteCU INT
DECLARE @curByteCU INT
SELECT @maxByteCU = DATALENGTH(COLUMNS_UPDATED()),
@curByteCU = 1
WHILE @curByteCU <= @maxByteCU BEGIN
DECLARE @cByte INT
SET @cByte = SUBSTRING(COLUMNS_UPDATED(), @curByteCU, 1)
DECLARE @curBit INT
DECLARE @maxBit INT
SELECT @curBit = 1,
@maxBit = 8
WHILE @curBit <= @maxBit BEGIN
IF CONVERT(BIT, @cByte & POWER(2, @curBit - 1)) <> 0 BEGIN
SET @ColId = cast( CONVERT(VARCHAR, 8 * (@curByteCU - 1) + @curBit) as int)
select @ColumnName = [Name]
FROM syscolumns
WHERE id = @idTable and colid = @ColId
SET @Columns_Updated = @Columns_Updated + ',' + @ColumnName
END
SET @curBit = @curBit + 1
END
SET @curByteCU = @curByteCU + 1
END