this is the first time I am working with an XML input in SQL. 

I created the following procedure to insert all records from my XML string into my table which works well so far. 

Can someone tell me how I have to change this so that it only inserts a record as new if the itemID (every record in my XML has this as well) does not yet exist in my table, column itemID - otherwise it should update the existing record with the new data from the XML. 

I know how to use IF NOT EXISTS and UPDATE in general but am not sure how to realise this with an XML string as the input. 

My procedure (so far): 

ALTER PROCEDURE [dbo].[editor_UpdateQuestions]
    @xml xml
AS
BEGIN
    SET NOCOUNT ON;

    INSERT INTO editor_Questions
        (
            categoryID,
            question,
            sortID,
            modDate,
            modBy       
        )
    SELECT  ParamValues.x1.value('categoryID[1]', 'int'),
            ParamValues.x1.value('question[1]', 'nvarchar(1000)'),
            ParamValues.x1.value('sortID[1]', 'int'),
            GETDATE(),
            ParamValues.x1.value('modBy[1]', 'varchar(50)')
    FROM    @xml.nodes('/ranks/item') AS ParamValues(x1)

END


Example XML input:

&lt;ranks&gt;
    &lt;item&gt;&lt;itemID&gt;25&lt;/itemID&gt;&lt;categoryID&gt;1&lt;/categoryID&gt;&lt;question&gt;some text&lt;/question&gt;&lt;sortID&gt;1&lt;/sortID&gt;&lt;modBy&gt;abc&lt;/modBy&gt;&lt;/item&gt;
    &lt;item&gt;&lt;itemID&gt;12&lt;/itemID&gt;&lt;categoryID&gt;1&lt;/categoryID&gt;&lt;question&gt;some text 2&lt;/question&gt;&lt;sortID&gt;2&lt;/sortID&gt;&lt;modBy&gt;abc&lt;/modBy&gt;&lt;/item&gt;
    &lt;item&gt;&lt;itemID&gt;9&lt;/itemID&gt;&lt;categoryID&gt;1&lt;/categoryID&gt;&lt;question&gt;some text 3&lt;/question&gt;&lt;sortID&gt;3&lt;/sortID&gt;&lt;modBy&gt;abc&lt;/modBy&gt;&lt;/item&gt;
&lt;/ranks&gt;


Many thanks in advance for any help with this, Tim.


Question: Which Windows 7 to install?
Answer: For any PC with less than 3GB of RAM I would go for 32-bit Windows. If you plan on upgrading your RAM and you are sure you can get 64-bit drivers for all your hardware, go with 64-bit Windows. You probably won't find many Windows 7 drivers yet, but 64-bit Vista drivers should do fine. 

32-bit software usually runs fine on 64-bit Windows 7 (and Vista). Since I started using Vista 64-bit (around the time it got released), I've only experienced problems two times and only one was a complete failure. An average user should not have any problems using 32-bit software  when 64-bit is not available.