How to read XML through SQL Queries / procedures

  • Hi All,

    I have XML string stored in database column, by parsing the XML string I need to get some values into variables using SQL Queries / Procedures, Is it possible? Please provide the solution for this.

    Thanks in advance,

    Sankar

     

     

  • Rather store as XML, not varchar.

    Read BOL! There are plenty examples on how to manipulate XML.

    ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/a699d976-8099-4af1-a2f8-cd0e2bd57a83.htm

    Cheers,CrispinI can't die, there are too many people who still have to meet me!It's not a bug, SQL just misunderstood me!

  • As Crispin said there are many ways to do this. Here is one.

    CREATE TABLE #AppSettings

    ( SettingCode varchar(4) NOT NULL, SettingValues xml NOT NULL )

    INSERT INTO #AppSettings

    VALUES ( 'SEC', '<SecurityOptions ChangePasswordPromptDays="0" NumberOfLoginAttemptsAllowed="0" />' )

     

    DECLARE @ChangePasswordPromptDays int, @NumberOfLoginAttemptsAllowed int

          --get current value

          SELECT

                @ChangePasswordPromptDays = SettingValues.value('(//SecurityOptions/@ChangePasswordPromptDays)[1]', 'integer'),

                @NumberOfLoginAttemptsAllowed = SettingValues.value('(//SecurityOptions/@NumberOfLoginAttemptsAllowed)[1]', 'integer')

          FROM   #AppSettings

          WHERE  SettingCode = 'SEC'

     

          SELECT @ChangePasswordPromptDays, @NumberOfLoginAttemptsAllowed

         

    DROP TABLE #AppSettings

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

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