爲什麼我的CTE不能從我的上次選擇中訪問?我問具體我如何列出我的熱膨脹係數,我簡單的東西,如我如何分離的最後兩個CTE未被識別
with ParentsIdsWhoHaveInventoryWithManifests_CTE(brokerIds)
as (...)
...)
select someField from ParentsIdsWhoHaveInventoryWithManifests_CTE
;with SpecificBrokersTicketIds_CTE(ticketIds)
as (...)
select someFieldfrom ParentsIdsWhoHaveInventoryWithManifests_CTE
;with ProductionIdsWhichHaveManifests_CTE(productionIds)
as (...)
select productionIds from ProductionIdsWhichHaveManifests_CTE
;with InventoryRow_CTE(row)
as (select row from Inventory where TicketId = @TicketId)
;with InvenotrySection_CTE(section)
as (select section from Inventory where TicketId = @TicketId)
select @ManifestId = ManifestId from Productions p where p.ProductionId = @ProductionId
select @ProductionId as ProductionId_Used
select @ManifestId as ManifestId_Used
select @TicketId = TicketId from inventory where ProductionId = @ProductionId
...
update Venue_ManifestDetails
set Row = row from InventoryRow_CTE,
Section = section from InvenotrySection_CTE
where TicketId = @TicketId
問題是,它並不在我的更新認識InventoryRow_CTE
或InvenotrySection_CTE
的CTE聲明。
可以甲肝一個'與'(bur多個cte從句)和一個'select'每個cte。這是語法! – 2014-09-19 00:21:46
CTE僅適用於隨後的聲明。看到這個更多的信息:http://stackoverflow.com/questions/6840168/scope-of-an-cte-in-sql-server-2005 – sgeddes 2014-09-19 00:22:58
但我想我的最後2個CTE擺脫這種模式,並能要做到這一點,但你說這是不可能的? – PositiveGuy 2014-09-19 00:24:05