I have the following code:begin trancreate table test1 (id int identity, ref char(1) check (ref=1))create table test2 (id int identity, ref char(1) check (ref=2))insert into test1select '1'union all select '1'gocreate view testasselect * from test1union all select * from test2go--select max(id) from testdeclare @id int , @sql nvarchar(max) , @params nvarchar(max) , @col varchar(100) , @tbl varchar(100) , @column varchar(100) , @table varchar(100) , @output intselect @column = 'id' , @table = 'test'set @params = '@output INT output'set @sql = 'select @output = max('+@column+') from '+@tableselect @sqlexec sp_executesql @sql,@params, @output = @idrollback tranI want to get the same results as the query 'select max(id) from test', but I have to build the sql dynamically, as I don't know the table or column name until run time.So far, no success. Can anyone help??????Hearty head pats