• This produces the same output as your example.

    if OBJECT_ID('MyResult') is not null

    drop table MyResult

    create 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 all

    select 1,'Ramesh new',20,'HYDERABAD' ,12345678 union all

    select 1,'Ramesh new',20,'HYDERABAD' ,87654321

    declare @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 @sql

    exec sp_executesql @sql

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/