Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8531071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:23:58+00:00 2026-06-11T09:23:58+00:00

I have a query which is working fine. Is it possible that if the

  • 0

I have a query which is working fine.

Is it possible that if the table3’s column(Child) is only related to table 1 to show it under table 1 and not under table 2, but at the same time another (Child) has a parent in table 2 (which usually is the case) it will show under table 2 as its currently doing.

In other words Child column is directly under Table2’s row column name (Father), but occasionally it comes under Table1 with no relation to Table 2.

How can I out put that in a query for a treeview? I am assuming that I will have to program the out come in c# also with 3 for loops and in the second loop I can check if the column is grandchild or Child and make that as a second row or 2nd node of treeview, but I am having a problem building a query in sql. Any help is much appreciated.

The query below shows all Parent, then child then grand child(all well and working), but what is desired is at times child takes place of a father.

declare @x as xml
set @x =
(
SELECT distinct  
Table1.AssetSysID, Table1.Asset_ID , Table1.FromLR, Table1.Asset_ID + ', ' + Table1.[Desc2] as GarndFather,
Table2.ACISysID ,Table2.PAssetSysID, Table2.FeatureName + ', ' + Table2.[DESC] AS Father,
Table3.ITMSysID  ,Table3.Item_ID + ',' + Table3.[DESC] as Child
FROM  Table1 left outer join 
Table2 ON Table1.AssetSysID = Table2.PAssetSysID left outer join 
Table3 ON Table1.AssetSysID = Table3.AssetSysID AND Table2.ACISysID = Table3.ACISysID
where (Table1.AssetType = @AssetType)
for xml auto,root('xml')
)

Asp.Net Telerik Treeview DataBinding Code:

<DataBindings>
      <telerik:RadTreeNodeBinding DataMember="Table1" TextField="Assets" ValueField="AssetSysID"  ToolTip="Asset" ImageUrl="~/Images/DeleteIco.png"/>
      <telerik:RadTreeNodeBinding DataMember="Table2" TextField="Feature" ValueField="ACISysID" ToolTip="Feature" ImageUrl="~/Images/CutIco.png"/>
       <telerik:RadTreeNodeBinding DataMember="Table3" TextField="Equipment" ValueField="ITMSysID" ToolTip="Equipment" ImageUrl="~/Images/EditIco.png"/>

    </DataBindings> 

*Final Code:

 select Table1.AssetObjID as "@AssetObjID",
           Table1.Asset_ID as "@Asset_ID",
           Table1.FromLR as "@FromLR",
           Table1.AssetType + ', ' + Table1.StreetName + ', ' +  Table1.FromMunicNo   as "@FirstRow",
           (
           select Table2.ACIObjID as "@ACIObjID",
                  Table2.PAssetObjID as "@PAssetObjID",
                  Table2.Feature_ID + ', ' + Table2.FeatureName   AS "@ChildOfFirstRow",
                  (
                  select Table3.ITMObjID as "@ITMObjID",
                         Table3.Item_ID + ',' + Table3.[DESC] as "@GrandChildOfFirstRow"
                  from Table3
                  where Table1.AssetObjID = Table3.AssetObjID and 
                        Table2.ACIObjID = Table3.ACIObjID
                  for xml path('Table3'), type
                  )
           from Table2
           where Table1.AssetObjID = Table2.PAssetObjID
           for xml path('Table2'), type
           ),
(
           select Table3.ITMObjID as "@ITMObjID",
                         Table3.Item_ID + ',' + Table3.[DESC] as "@GrandChildOfFirstRow"
                  from Table3
                  where Table1.AssetObjID = Table3.AssetObjID and 
                        Table2.ACIObjID <> Table3.ACIObjID
                  for xml path('Table3'), type
)
    from Table1
    where Table1.AssetType = 'xxxx'
    for xml path('Table1'), root('xml')
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:24:00+00:00Added an answer on June 11, 2026 at 9:24 am

    Got an Idea from Mikael Eriksson and help from team lead @ work

         select Table1.AssetObjID as "@AssetObjID",
                   Table1.Asset_ID as "@Asset_ID",
                   Table1.FromLR as "@FromLR",
                   Table1.AssetType + ', ' + Table1.StreetName + ', ' +  Table1.FromMunicNo   as "@FirstRow",
                   (
                   select Table2.ACIObjID as "@ACIObjID",
                          Table2.PAssetObjID as "@PAssetObjID",
                          Table2.Feature_ID + ', ' + Table2.FeatureName   AS "@ChildOfFirstRow",
                          (
                          select Table3.ITMObjID as "@ITMObjID",
                                 Table3.Item_ID + ',' + Table3.[DESC] as "@GrandChildOfFirstRow"
                          from Table3
                          where Table1.AssetObjID = Table3.AssetObjID and 
                                Table2.ACIObjID = Table3.ACIObjID
                          for xml path('Table3'), type
                          )
                   from Table2
                   where Table1.AssetObjID = Table2.PAssetObjID
                   for xml path('Table2'), type
                   ),
    (
                   select Table3.ITMObjID as "@ITMObjID",
                                 Table3.Item_ID + ',' + Table3.[DESC] as "@GrandChildOfFirstRow"
                          from Table3
                          where Table1.AssetObjID = Table3.AssetObjID and 
                                Table2.ACIObjID <> Table3.ACIObjID
                          for xml path('Table3'), type
    )
            from Table1
            where Table1.AssetType = 'xxxx'
            for xml path('Table1'), root('xml')
    

    So It goes something like this:

    <Table1 atrributes......... FirstRow=".........."/>
    <Table2 atrributes......... ChildOfFirstRow="..........">
    <Table3 atrributes......... GrandChildOfFirstRow=".........."/>
    </Table2>
    <Table3 atrributes......... GrandChildOfFirstRow="This GrandChild took the importance as equal to ChildOfFirstRow"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query which is working fine, but I also want to
I have the following dynamic query which is working fine without the WHERE clause,
I have a Linq query which is working fine but i have noticed when
I have a query which is working fine: BULK INSERT ZIPCodes FROM 'e:\5-digit Commercial.csv'
I have this query, which was working fine. SELECT SUM(amount) FROM company.invoice_line WHERE item_id
i have been working on query which uses compute by clause for avg and
I have the following xpath query which seems to be working but I just
This query was working fine when the database was small, but now that there
I am trying to send notification emails(which is working fine) but have added the
I have this mysql query using PHP and first part is working fine, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.