SQL Server Developer Center > SQL Server Forums > SQL Server XML > Compare date attributes of two nodes using xml.exist
Ask a questionAsk a question
 

AnswerCompare date attributes of two nodes using xml.exist

  • Tuesday, October 27, 2009 4:10 AMSelvaKumar Chandrasekar Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
    I need to compare attributes of two nodes using xml.exist.

    declare @x xml
    declare @f bit
    set @x = '<root Somedate = "2002-01-01Z"/>'
    set @f = @x.exist('/root[(@Somedate cast as xs:date?) eq xs:date("2002-01-01Z")]')
    select @f

    Instead of the above code I need to have something like to compare two nodes.

    @x.exist('/root[(@Somedate cast as xs:date?) eq xs:date('/root[(@anotherdate cast as xs:date?')]')

    Help me if it is possible. Thanks in advance.

Answers

  • Tuesday, October 27, 2009 10:23 AMwBobAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    These two examples seem to work:

    declare @x xml
    declare @f bit
    set @x = '<root Somedate = "2002-01-01Z" anotherdate = "2002-01-01Z"/>'
    set @f = @x.exist('/root[(@Somedate cast as xs:date?) eq (@anotherdate cast as xs:date?)]')
    select @f
    GO
    
    
    declare @x xml
    declare @f bit
    set @x = '<root Somedate = "2002-01-01Z"><x anotherdate = "2002-01-01Z"/></root>'
    set @f = @x.exist('/root[@Somedate = x/@anotherdate]')
    select @f
    

All Replies

  • Tuesday, October 27, 2009 10:23 AMwBobAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    These two examples seem to work:

    declare @x xml
    declare @f bit
    set @x = '<root Somedate = "2002-01-01Z" anotherdate = "2002-01-01Z"/>'
    set @f = @x.exist('/root[(@Somedate cast as xs:date?) eq (@anotherdate cast as xs:date?)]')
    select @f
    GO
    
    
    declare @x xml
    declare @f bit
    set @x = '<root Somedate = "2002-01-01Z"><x anotherdate = "2002-01-01Z"/></root>'
    set @f = @x.exist('/root[@Somedate = x/@anotherdate]')
    select @f