CREATE TABLE #Users(id INT PRIMARY KEY, name VARCHAR(100)...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

CREATE TABLE #Users(id INT PRIMARY KEY, name VARCHAR(100), suggestions XML);

INSERT INTO #Users
SELECT 1, 'Bob', N'<Products>
                       <Product id="1" score="1"/>
                       <Product id="2" score="5"/>
                       <Product id="3" score="4"/>
                   </Products>'
UNION ALL
SELECT 2, 'Jimmy', N'<Products>
                       <Product id="6" score="3"/>
                    </Products>';
                    


DECLARE @userId INT = 1,
        @suggestions XML =  N'<Products>
                              <Product id="2" score="5"/>
                              <Product id="3" score="2"/>
                              <Product id="7" score="1" />
                          </Products>';
           
           
/*
UPDATE #Users
SET suggestions.modify(... sql:variable("@suggestions") ... );
WHERE id = @userId;
*/

SELECT *
FROM #Users;

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results