TSQL that outputs to XML

  • Hello,

    I have a query that outputs as XML and am having trouble with one part of it.

    I have a table called StudentPrograms:

    CREATE TABLE [dbo].[StudentPrograms](

    [StudentID] [char](10) NULL,

    [Catalog] [varchar](10) NULL,

    [Degree] [char](40) NULL,

    [Major] [char](40) NULL,

    [Minor] [char](40) NULL,

    [Concentration] [char](40) NULL

    ) ON [PRIMARY]

    With data such as:

    Insert into StudentPrograms

    values

    ('111111111', '2013-14', 'BA', 'AC', 'HN', 'EL'),

    ('222222222', '2013-14', 'BS', 'AC', 'HN', NULL),

    ('333333333', '2015-16', 'AS', 'AC', NULL, 'EL'),

    ('444444444', '2015-16', 'MBA', 'MK', 'MG', NULL),

    ('555555555', '2013-14', 'NS', 'HC', NULL, NULL)

    I need this in XML formatted like this:

    <student id="111111111">

    <educational_goal type="final">

    <student_path>

    </student_path>

    </educational_goal>

  • Welcome. Thanks for posting usable DDL, test data and desired results. What have you tried so far?

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Duplicate post:

    http://www.sqlservercentral.com/Forums/Topic1752396-149-1.aspx

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Sorry, didn't realize I posted this twice. The other post is more complete with details.

    Thank you.

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

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