我有一个结果使用sql pivot现在我希望将其复制到temperory表。如何动态创建临时表并插入数据。我已添加动态查询的输出
select
testresultid,customername
, MAX([val1]) AS [val1],MAX([11]) AS [val2],MAX([11]) AS [val2],MAX([11])
答案 0 :(得分:1)
要创建临时表,您只需在into #tempTableName
示例之前添加from statement
:
select
testresultid,customername
, MAX([Compliant Information Disclosure1]) AS [Compliant Information DisclosurePostEvent],MAX([11]) AS [Compliant Information DisclosureFileValidationOverall],MAX([11]) AS [Compliant Information DisclosureCombinedOverallOutcome],MAX([11]) AS [Compliant Information DisclosureHasOutcome],MAX([Heading1]) AS [HeadingPostEvent],MAX([11]) AS [HeadingFileValidationOverall],MAX([11]) AS [HeadingCombinedOverallOutcome],MAX([01]) AS [HeadingHasOutcome],MAX([Internal Process Compliance1]) AS [Internal Process CompliancePostEvent],MAX([11]) AS [Internal Process ComplianceFileValidationOverall],MAX([11]) AS [Internal Process ComplianceCombinedOverallOutcome],MAX([11]) AS [Internal Process ComplianceHasOutcome],MAX([Meets Customer Needs1]) AS [Meets Customer NeedsPostEvent],MAX([01]) AS [Meets Customer NeedsFileValidationOverall],MAX([01]) AS [Meets Customer NeedsCombinedOverallOutcome],MAX([11]) AS [Meets Customer NeedsHasOutcome],MAX([Regulatory Compliance1]) AS [Regulatory CompliancePostEvent],MAX([01]) AS [Regulatory ComplianceFileValidationOverall],MAX([01]) AS [Regulatory ComplianceCombinedOverallOutcome],MAX([11]) AS [Regulatory ComplianceHasOutcome]
INTO #myTemp -- INSERT IT HERE
FROM (
SELECT
p.testresultid, p.customername,
答案 1 :(得分:0)
您是否可以使用以下查询?
SELECT * INTO NEW_TABLE_NAME FROM (Your entire query here) as data
它将根据您的数据
创建表格