Lo que quiero lograr es recorrer cada columna de una tabla y verificar si tiene un cambio con la funcion update(colum), pero al parecer toma la variable donde guardo la columna como un argumento valido.
DECLARE @field INT ,
@maxfield INT ,
@fieldname VARCHAR(128) ,
@TableName VARCHAR(128) ,
@SelectUpdate Varchar(100) = 'Select '
SELECT @field = 0,
@maxfield = MAX(ORDINAL_POSITION)
FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @TableName
WHILE @field < @maxfield
BEGIN
SELECT @field = MIN(ORDINAL_POSITION)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @TableName
AND ORDINAL_POSITION > @field
SELECT @fieldname = COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @TableName
AND ORDINAL_POSITION = @field
IF (UPDATE(@fieldname))
BEGIN
if (@field = 1)
select @SelectUpdate = @SelectUpdate + @fieldname
else
select @SelectUpdate = @SelectUpdate +', ' +@fieldname
END
END