Hello,I was trying to use the code below to create a .txt file to send completed cases to our clients. It "almost" works as I want it to. The issue is that I need to pass a second parameter 'ineterestID' from dbo.eInterest (line B) to lines B1 and B2 to pull the corresponding addresses and bankruptcies if any exist.Currently the output looks as such:A (Case Information)B (defendant1)B (defendant2)B (defendant3)B1 (address for defendant1)B1 (address for defendant2)B2 (bankruptcy for defendant3)CCCI need it to look like :A (Case Information)B (defendant1)B1 (Address for defendant 1)B (defendant2)B1 (Address for defendant 2)B (defendant3)B2 (bankruptcy for defendant 3)C CC(I left the C lines there as they are in the code below but are not relevant to the issue at hand.Do I have to do this a different way (using cursors) or is there a way to get the desired result from this method?Any help would be appreciated.Thank you,George;WITH outpQAS(SELECT 'A' AS Ord, CaseNumber, 'A|' + CaseNumber + '|' + CAST(BRTNumber AS VARCHAR(11)) + '|' + IsNull(LegalDescription, '') + '|' + IsNull(replace(convert(char(10), CoverDate, 101), '/', ''), '') + '|' + IsNull(SumOut, '') AS ExtractFROM CityCollection.dbo.FileInfo UNION ALL SELECT 'A1', A.CaseNumber, 'A1|' + '|' + IsNull(B.LienInstrument, '') + '|' + B.LienNumber + '|' + Cast(B.LienAmount AS VARCHAR(20)) + '|' + IsNull(replace(LienDate, '/', ''), '') + '|' + IsNull(B.LienReason, '') AS ExtractFROM CityCollection.dbo.FileInfo AJOIN CityCollection.dbo.municipalLiens B ON B.CaseNumber = A.CaseNumberUNION ALL SELECT 'B', A.CaseNumber, 'B|' + '|' + IsNull(C.defTypeCode, '') + '|' + IsNull(C.eInterestFirst, '') + '|' + IsNull(C.eInterestMiddle, '') + '|' + IsNull(C.eInterestLast, '') + '|' + IsNull(C.eInterestAlias, '') + '|' + IsNull(C.eInterestCom, '') + '|' + '|' + '|' + '|' + '|' + IsNull(C.eInterestAdd, '') + '|' + IsNull(C.eInterestAdd2, '') + '|' + IsNull(C.eInterestCity, '') + '|' + IsNull(C.eInterestState, '') + '|' + IsNull(C.eInterestZip, '') + '|' + IsNull(C.eInterestCountry, '') + '|' + IsNull(C.eInterestDoc, '') + '|' + Cast(interestID AS VARCHAR(MAX)) AS ExtractFROM CityCollection.dbo.FileInfo AJOIN CityCollection.dbo.eInterest C ON C.CaseNumber = A.CaseNumberUNION ALL SELECT 'B1', A.CaseNumber, 'B1|' + '|' + IsNull(D.address, '') + '|' + '|' + IsNull(D.city, '') + '|' + IsNull(D.state, '') + '|' + IsNull(D.zip, '') + '|' + IsNull(D.country, '') AS ExtractFROM CityCollection.dbo.FileInfo AJOIN CityCollection.dbo.addresses D ON D.CaseNumber = A.CaseNumber UNION ALL --FROM authors a --INNER JOIN titleauthor ta ON a.au_id = ta.au_id --JOIN titles t ON ta.title_id = t.title_idSELECT 'B2', A.CaseNumber, 'B2|' + '|' + IsNull(E.suiteNumber, '') + '|' + Cast(E.BDate AS VARCHAR(11)) + '|' + IsNull(E.Chapter, '') + '|' + IsNull(E.vs, '') AS ExtractFROM CityCollection.dbo.FileInfo AJOIN CityCollection.dbo.banks E ON E.CaseNumber = A.CaseNumberUNION ALLSELECT 'B3', A.CaseNumber, 'B3|' + '|' + F.docType + '|' + IsNull(Cast(F.DocAmount AS VARCHAR(50)), '') + '|' + IsNull(replace(convert(char(10), docDate, 101), '/', ''), '') + '|' + IsNull(replace(convert(char(10), recDate, 101), '/', ''), '') + '|' + IsNull(F.bkpage, '') + '|' + F.grantee + Cast(F.documentID AS VARCHAR(Max)) AS ExtractFROM CityCollection.dbo.FileInfo A JOIN CityCollection.dbo.Documents F ON F.CaseNumber = A.CaseNumber UNION ALLSELECT 'C', A.CaseNumber, 'C|' + IsNull(G.grantorDef,'') + '|' + IsNull(G.grantor, '') AS ExtractFROM CityCollection.dbo.FileInfo A JOIN CityCollection.dbo.documents G ON G.CaseNumber = A.CaseNumberUNION ALLSELECT 'C', A.CaseNumber, 'C|' + IsNull(H.TADef,'') + '|' + IsNull(H.TaxAccts, '') AS ExtractFROM CityCollection.dbo.FileInfo A JOIN CityCollection.dbo.FileInfo H ON H.CaseNumber = A.CaseNumberUNION ALLSELECT 'C', A.CaseNumber, 'C|' + IsNull(I.RegDef,'') + '|' + IsNull(I.Registry, '') AS ExtractFROM CityCollection.dbo.FileInfo A JOIN CityCollection.dbo.FileInfo I ON I.CaseNumber = A.CaseNumberUNION ALLSELECT 'C', A.CaseNumber, 'C|' + IsNull(J.CType, '') + '|' + IsNull(J.plaintiffName,'') + '|' + IsNull(J.plaintiffAdd1, '') + '|' + IsNull(J.plaintiffCity, '') + '|' + IsNull(J.plaintiffState, '') + '|' + IsNull(J.plaintiffZip, '') + '|' + '|' + IsNull(J.defendantName, '') + '|' + IsNull(J.defendantAdd1, '') + '|' + IsNull(J.defCity, '') + '|' + IsNull(J.defState, '') + '|' + IsNull(J.defZip, '') + '|' + '|' + IsNull(J.Court, '') + '|' + IsNull(J.CaseID, '') + '|' + IsNull(J.JAmt, '') + '|' + IsNull(replace(convert(VarChar(10), JDate, 101), '/', ''), '') + '|' + IsNull(replace(convert(VARCHAR(10), revivedDate, 101), '/', ''), '') AS ExtractFROM CityCollection.dbo.FileInfo A JOIN Acme.new_judgment_system.dbo.selected_compiled_clean J ON J.CaseNumber = A.CaseNumber)SELECT Extract FROM outpQ ORDER BY CaseNumber, Ord