strange behavior of SQL Server when sum nodes's values in XML

后端 未结 4 1730
后悔当初
后悔当初 2021-01-20 18:11

I ask a question about sum node\'s values:

sum some xml nodes values in sql server 2008

Please consider this code:

Declare @xml xml 
set @xml         


        
4条回答
  •  太阳男子
    2021-01-20 18:46

    Try this is working with BIGINT:

    DECLARE @SearchKeyWords XML 
    
    SET @SearchKeyWords =
    '
        1000000000 
        234650 
        0 
    ' 
    
    DECLARE @TempSearchKeyWords TABLE
            (
                SearchKeyWord BIGINT
            )
    
    INSERT INTO @TempSearchKeyWords                     
    SELECT SearchKeyWords.SearchKeyword.value('.',' bigint ') AS SearchKeyword             
    FROM @SearchKeyWords.nodes('/Parent/Child') AS SearchKeyWords(SearchKeyword)
    
    SELECT SUM(SearchKeyWord) FROM @TempSearchKeyWords
    

提交回复
热议问题