Knowledge: SQL to Iterate through Child Data Room items
Back
Knowledge
Title*SQL to Iterate through Child Data Room items
ManualReporting
Created20/02/2018
DetailDECLARE @ItemID as int = 7423
DECLARE @AllRecords as bit = 0
DECLARE @ApplicationID as int = 1147
IF (@AllRecords = 1)
BEGIN
IF OBJECT_ID('tempdb..#TempClaims') IS NOT NULL
DROP TABLE #TempClaims
SELECT *
INTO #TempClaims
FROM ClaimClaimRelationships WHERE ParentClaimID = @ItemID
Declare @Id int
WHILE EXISTS(SELECT * FROM #TempClaims)
Begin
Select Top 1 @Id = Id From #TempClaims
SET @ItemID = (Select ChildClaimID FROM #TempClaims WHERE Id=@ID)
SELECT * FROM Claims WHERE ID=@ItemID
Delete #TempClaims Where Id = @Id
End
Drop Table #TempClaims
END
ELSE
BEGIN
SELECT * FROM Claims WHERE ID=@ItemID AND ApplicationID=@ApplicationID
END
Additional Manual Locations
Administration | Data Actions | SQL |