Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Creare un elenco di query dinamiche da una matrice in SQL Server 2008

Ti manca l'istruzione from e where qui:

while @i <= @cnt
    begin
        select @sql = 
            'select t.objectID, t.DocID as ' + field + 
            ' into #tmp_auditlog_' + field + 
            ' from #tmp_auditlog_subselection t where Details like ' + details FROM #tmp_auditlog_fields WHERE id = @i
        exec sp_executesql @sql
        select @i = @i + 1
  end