VARBINARY(MAX) to XML

  • I have a column in VARBINARY(MAX) and I want its data to convert it to XML

    Can someone please provide me a simple query.I tried looking on other websites but no luck .they are quite confusing..

  • Assuming that the contents are already valid XML, then

    ALTER TABLE <table name> ALTER COLUMN <column name> XML

    should do it.

    If the contents aren't valid XML, you'll have to fix that first.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Gila,

    I am looking for a query to convert data in VARBINARY(MAX) to be displayed in XML

    can you help

  • It doesn't appear there is much to do to convert from varbinary(max) to XML;

    DECLARE @test-2 TABLE (

    varbincol varbinary(max)

    )

    INSERT INTO @test-2 VALUES ( CAST(N'<XML><!-- A comment --></XML>' AS varbinary(MAX)))

    SELECT CAST(varbincol AS xml)

    FROM @test-2

    Doesn't it solve your issue?

    -- Gianluca Sartori

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

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