How to convert SQL bit to XML boolean?

  • Hi,

    I have to migrate some data of a SQL table to XML. Now I have to convert a table column of type bit to a XML element of type Boolean.

    |IsSet|

    1

    0

    to

    <root>

    <IsSet>True</IsSet>

    <IsSet>False</IsSet>

    </root>

    How can I achieve this?

    Regards,

    Andreas

  • Would something like the following code do the job?

    DECLARE @t TABLE (IsSet bit)

    INSERT INTO @t SELECT 1 UNION ALL SELECT 0

    SELECT

    CASE WHEN IsSet=0 THEN 'False' ELSE 'True' END AS IsSet

    FROM @t

    FOR XML PATH(''), TYPE, ELEMENTS, ROOT('root')

    /* result set:

    <root>

    <IsSet>True</IsSet>

    <IsSet>False</IsSet>

    </root>

    */



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

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

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