August 14, 2013 at 5:28 am
I am trying to build this view with a cte and I am getting the error msg:
Msg 252, Level 16, State 1, Procedure SubQryTradeDiscItemLevelSummary, Line 3
Recursive common table expression 'TradeDiscDealLevelSummary' does not contain a top-level UNION ALL operator.
code:
Create View dbo.SubQryTradeDiscItemLevelSummary
AS
WITH SubQryTDAssignments AS
(
SELECT DISTINCT Include,Vndnbralt,Vndname,NumberofDeals,PotentialClaimAmt,Lastupdateddate,AssignedAuditors,Comments,Auditstatuscode,ID,RecordSelector
FROM TradeDiscAssignments
--WHERE AssignedAuditors Like '%" & GBL_Username & "%'
),
TradeDiscDealLevelSummary AS
(
SELECT DISTINCT SubQryTDAssignments.RecordSelector AS REC, TradeDiscDealLevelSummary.*, SubQryTDAssignments.Comments
FROM TradeDiscDealLevelSummary
INNER JOIN SubQryTDAssignments
ON TradeDiscDealLevelSummary.VndNbr = SubQryTDAssignments.Vndnbralt
WHERE SubQryTDAssignments.RecordSelector = '-1'
),
SubQryTradeDiscItemLevelSummary1 AS
(
SELECT DISTINCT SubQryTradeDiscDealLevelSummary.RecordSelector AS REC, TradeDiscItemLevelSummary.*, SubQryTradeDiscDealLevelSummary.Comments
FROM TradeDiscItemLevelSummary
INNER JOIN (TradeDiscDealLevelSummary
INNER JOIN SubQryTradeDiscDealLevelSummary
ON TradeDiscDealLevelSummary.TradeDiscDealLevelSummaryId = SubQryTradeDiscDealLevelSummary.TradeDiscDealLevelSummaryId)
ON TradeDiscItemLevelSummary.TradeDiscDealLevelSummaryId = SubQryTradeDiscDealLevelSummary.TradeDiscDealLevelSummaryId
WHERE SubQryTradeDiscDealLevelSummary.RecordSelector = '-1'
)
Select * From SubQryTradeDiscItemLevelSummary1
August 14, 2013 at 5:41 am
Difficult to see what you're trying to do here, since your TradeDiscDealLevelSummary CTE attempts to select from itself.
John
August 14, 2013 at 5:52 am
If the query doesn't work, why try to construct a view out of it? Drop the CREATE VIEW part until you've got it working. It's just noise.
Start again, your query doesn't make any sense at all. Start simple and build incrementally, testing at each step. Use table aliases.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy