January 11, 2011 at 1:47 pm
Hello,
Can anyone please help me to (Pseudocode will be perfect) to translate below query to SSIS steps?
My Data Source is is Raw file and output will be in Raw file too. I can use Cache Connection to cache the whole dataset if needed.
I am familiar with SSIS steps but never did Recursive 🙁
Source file structure:
AgentId,UplineAgentId,Position
Recursive CTE Query:
;WITH AgentsWithSelfUprRecords AS
(
SELECT AgentId
FROM pfsHier
WHERE AgentId = UplineAgentId AND Position = 'UPR'
),
T AS
(
SELECT H.UplineAgentId, H.AgentId, 1 As Depth
FROM AgentsWithSelfUprRecords A
INNER JOIN pfsHier H ON H.UplineAgentId != H.AgentId AND H.AgentId = A.AgentId AND H.Position = 'UOS'
UNION ALL
SELECT T.UplineAgentId, H.AgentId, T.Depth + 1 AS Depth
FROM T
INNER JOIN pfsHier H ON H.AgentId != H.UplineAgentId AND H.UplineAgentId = T.AgentId AND H.Position = 'UPR'
)
SELECT *
FROM T
UNION ALL
SELECT A.AgentId AS UplineAgentId, A.AgentId, 0 AS Depth
FROM AgentsWithSelfUprRecords A
ORDER BY UplineAgentId, Depth
Thanks and any help will be much appreciated.
Thanks again,
Z
January 11, 2011 at 7:17 pm
zahidullislam (1/11/2011)
Hello,Can anyone please help me to (Pseudocode will be perfect) to translate below query to SSIS steps?
My Data Source is is Raw file and output will be in Raw file too. I can use Cache Connection to cache the whole dataset if needed.
I am familiar with SSIS steps but never did Recursive 🙁
Source file structure:
AgentId,UplineAgentId,Position
Recursive CTE Query:
;WITH AgentsWithSelfUprRecords AS
(
SELECT AgentId
FROM pfsHier
WHERE AgentId = UplineAgentId AND Position = 'UPR'
),
T AS
(
SELECT H.UplineAgentId, H.AgentId, 1 As Depth
FROM AgentsWithSelfUprRecords A
INNER JOIN pfsHier H ON H.UplineAgentId != H.AgentId AND H.AgentId = A.AgentId AND H.Position = 'UOS'
UNION ALL
SELECT T.UplineAgentId, H.AgentId, T.Depth + 1 AS Depth
FROM T
INNER JOIN pfsHier H ON H.AgentId != H.UplineAgentId AND H.UplineAgentId = T.AgentId AND H.Position = 'UPR'
)
SELECT *
FROM T
UNION ALL
SELECT A.AgentId AS UplineAgentId, A.AgentId, 0 AS Depth
FROM AgentsWithSelfUprRecords A
ORDER BY UplineAgentId, Depth
Thanks and any help will be much appreciated.
Thanks again,
Z
I can't help much with SSIS because I don't use it and I sure don't know what UPR or UOS is. I can tell you that the CTE called "T" is a recursive CTE designed to produce a hierarchical listing.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply