INSERT INTO temp table from unknown number and name of columns (from dynamic PIVOT query)
问题 I have a dynamic query as shown below. The @ColumnNames param has multiple columns this pivot is using. @ID and @Apartment_ID come from insert parameters. SET @DynamicSQL = 'select id, name, address, phone, remarks, ' + **@ColumnNames** + ' from (select b.id, name, criteria_id, impact_value, remarks from dbo.User u inner join dbo.ID b on b.id = u.id where b.Instance_ID = '+ **@Id** + 'and ownerID in (select * from fnSplitString(''' + **@Apartment_ID** + + ''',' + ''',''' + '))' + ') as t