I think you need dynamic SQL there. So maybe something like this
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
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)