为什么我的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