0

我在尝试在并行数据仓库中TableA使用 Joining ofTableA编写更新语句 On 时遇到困难,但它引发了异常。TableBTableC

例如:简单示例

Update TableA
Set EnableFlag='Y'

From TableA INNER JOIN TableB ON A.ID=B.ID  
INNER JOIN TableC ON A.ID=C.ID

这可能是什么原因造成的?

4

1 回答 1

0

UPDATEon PDW 有点奇怪,并且您发现有一些限制。基本上你需要先做一个CTAS。然后,您可以在 UPDATE 期间加入 CTAS 表,或者只是重命名旧表并通过重命名替换为新的 CTAS 表。这是 CTAS 的示例,然后在 UPDATE 期间加入:

CREATE TABLE CTAS_ACS
WITH (DISTRIBUTION = REPLICATE)
AS
SELECT 
 ISNULL(CAST([EnglishProductCategoryName] AS NVARCHAR(50)),0) AS [EnglishProductCategoryName]
,ISNULL(CAST([CalendarYear] AS SMALLINT),0) AS [CalendarYear]
,ISNULL(CAST(SUM([SalesAmount]) AS MONEY),0) AS [TotalSalesAmount]
FROM  dbo.factInternetSales s
JOIN  dbo.DimDate d               ON s.OrderDateKey            = d.DateKey
JOIN  dbo.DimProduct p            ON s.ProductKey              = p.ProductKey
JOIN  dbo.DimProductSubCategory u ON p.[ProductSubcategoryKey] = u.[ProductSubcategoryKey]
JOIN  dbo.DimProductCategory c    ON u.[ProductCategoryKey]    = c.[ProductCategoryKey]
WHERE [CalendarYear] = 2004
GROUP BY [EnglishProductCategoryName]
,        [CalendarYear];

UPDATE AnnualCategorySales
SET   AnnualCategorySales.TotalSalesAmount = CTAS_ACS.TotalSalesAmount
FROM  CTAS_ACS
WHERE CTAS_ACS.[EnglishProductCategoryName] = AnnualCategorySales.[EnglishProductCategoryName]
AND   CTAS_ACS.[CalendarYear]               = AnnualCategorySales.[CalendarYear];

虽然上述模式是典型的模式,但在您的情况下,我认为以下方法会起作用(在我的脑海中):

Update TableA
Set EnableFlag='Y'
WHERE ID IN (
 SELECT B.ID
 FROM TableB B
 INNER JOIN TableC C ON B.ID=C.ID
)
于 2016-08-24T10:14:08.900 回答