I am passing an xml string to stored procedure in SQL Server for inserting 10000 records to my table. In this when I call this stored procedure. Want to check the SQL Server table with that xml string which I am passing, if the record exists I don't want to insert, if it is new record that record alone have to insert.Give some solution. Thanks.
ALTER procedure [dbo].[SP_CMSUSER1]
(@xmlString ntext)
as
begin
DECLARE @idoc INT
DECLARE @data nvarchar(100)
EXEC sp_xml_preparedocument @idoc OUTPUT, @xmlString
INSERT INTO dbo.Seg_RecipientsTemp (ContactID,first_name,last_name,company,email,last_updated)
SELECT ContactID,
first_name,
last_name,
company,
email,
last_updated FROM OPENXML(@idoc,
'/NewDataSet/ContactData', 6)
WITH
(ContactID int ,
first_name nvarchar(50),
last_name nvarchar(50),
company nvarchar(max),
email nvarchar(100),
last_updated datetime
)
end
My Xml is:
<NewDataSet>
<Table>
<ContactID>2</ContactID>
<last_name>klklk</last_name>
</Table>
<Table>
<ContactID>4</ContactID>
<first_name>k</first_name>
<last_name>kk</last_name>
<company>k</company>
</Table>
<Table>
<ContactID>6</ContactID>
<first_name>naveen</first_name>
<last_name />
<company>inno</company>
</Table>
<Table>
<ContactID>7</ContactID>
<first_name>sridar</first_name>
<last_name />
<company>mahindara</company>
</Table>
<Table>
<ContactID>1</ContactID>
<first_name>terst</first_name>
</Table>
<Table>
<ContactID>2</ContactID>
<first_name />
<last_name>ask</last_name>
<company />
</Table>
</NewDataSet>
ContactID
's that don't exist indbo.Seg_RecipientsTemp
but exist in XML data? Do you want to UPDATE the data indbo.Seg_RecipientsTemp
forContactID
's that do exist in XML data? – Stylusxml
data type, and it would be far better to use that if possible – Vallonia