declare @strSQL varchar(max)
declare @cols varchar(max)
declare @FileNo int
set @fileNo = 101
set @cols = stuff((select ',' + OriginalColumnName from File_Column_Master where Fileno = @FileNo for xml path('')), 1, 1, '')
set @strSQL = 'select ID, FileNo, Name, Address, Company, Phone, Email, ' + @cols + ' from yourtable where id = ' + cast(@FileNo as varchar)
exec(@strSQL)
|