更新时间:2023-02-18 23:37:03
尝试创建一个临时表来临时插入数据,然后从该表中选择:
Try creating a temporary table to insert the data temporarily, then select from that table:
DECLARE @MydynamcSQL varchar(1000);
SET @MydynamcSQL = 'select fieldname1, fieldname1 from table1';
CREATE TABLE #Result
(
fieldname1 varchar(1000),
fieldname2 varchar(1000)
)
INSERT #Result Exec(@MydynamcSQL)
SELECT fieldname1, fieldname1 -- here you have "static SELECT with field names"
FROM #Result
DROP TABLE #Result