Dynamic Query

  • Hi

    Here I have a Table such as the following :

    IDintPrimary Key

    TitlenVarchar(500)

    Parent_IDint

    There is a one to many relation-ship between Parent_ID and ID.

    The problem is that i need sqlServer to generate an xml as follows :

    <Items>

    <Item Title="One" >

    <Item Title="OneOne" >

    <Item Title="OneOneOne"

    </Item>

    <Item Title="OneTwo" />

    </Item>

    <Item Title="Two" />

    <Item Title="Three" />

    <Item Title="Four" >

    <Item Title="FourOne" />

    <Item Title="FourTwo" >

    <Item Title="FourTwoOne" />

    <Item Title="FourTwoTwo" />

    <Item Title="FourTwoThree" >

    <Item Title="FourTwoThreeOne" />

    <Item Title="FourTwoThreeTwo" />

    </Item>

    </Item>

    </Item>

    </Items>

    As you might have been understood, there might be multiple inner joins within one table per record.

    I worked out a bad way out for it which I'm sure is the most horrendous. So that, I'm thinking of the best possible solution, t-sql might offer.

    Thanks for your upcoming answers

    Kind Regards

  • You know, the people that help out here are all un-paid volunteers. Providing the DDL scripts (CREATE TABLE, CREATE INDEX, etc.) for the tables affected, and INSERT statements to put some test data into those tables that shows your problem will go a long way in getting people to look at your issue and help you out. Please include code for what you have already tried. Don't forget to include what your expected results should be, based on the sample data provided. As a bonus to you, you will get tested code back. For more details on how to get all of this into your post, please look at the first link in my signature.

    Notice how nobody has responded? That's why - you haven't made it easy for us to help you, so we just pass on it.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • I guess I found what I need.

    Thank you.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply