Is it possible to use a variable in UPDATE() which check if a column is updated or not?
here is my sample code:
DECLARE @ColumnCount int
DECLARE @ColumnC
A few things: You may want to handle the first time through the loop because the name would not have changed the first time through. You may want to handle when @ColumnName is null because that would mean your query did not return a row although your query below should always return a value.
DECLARE @ColumnCount INT
DECLARE @ColumnCounter INT
DECLARE @ColumnName NVARCHAR(max)
DECLARE @temp varchar(max)
SET @ColumnCounter = 0
SELECT @ColumnCount = Count(c.column_name)
FROM information_schema.columns c
WHERE c.table_name = 'Province'
WHILE @ColumnCount >= @ColumnCounter
BEGIN
SET @ColumnName = NULL
SELECT @ColumnName = c.column_name
FROM information_schema.columns c
WHERE c.table_name = 'Province'
AND c.ordinal_position = @ColumnCounter
IF ( @ColumnName != @temp )
BEGIN
--do something
END
SET @temp = @ColumnName
SET @ColumnCounter = @ColumnCounter + 1
END