if OBJECT_ID('MyResult') is not null drop table MyResultcreate table MyResult( TBLID int identity(1,1), ID int, patientName varchar(10), age int, city varchar(100), Mobile int)insert MyResult(ID, patientName, age, city, Mobile) select 1,'Ramesh',20,'HYD',12345678 union allselect 1,'Ramesh new',20,'HYDERABAD' ,12345678 union allselect 1,'Ramesh new',20,'HYDERABAD' ,87654321declare @sql nvarchar(max) select @sql = COALESCE(@sql + ' union all ', '') + 'select ''' + c.name + ''' as [Column], Max(Cast([' + c.name + '] AS VarChar(MAX))) as [OldValue], Min(Cast([' + c.name + '] AS VarChar(MAX))) as [NewValue] from MyResult having Min(Cast([' + c.name + '] AS VarChar(MAX))) <> Max(Cast([' + c.name + '] AS VarChar(MAX)))' from sys.columns c inner join sys.objects o on c.object_id = o.object_id and o.type = 'u' where o.object_id = object_id('MyResult')order by c.column_id --select @sqlexec sp_executesql @sql