T-Sql Modify Insert SProc To Update If Exists.
Posted
by Goober
on Stack Overflow
See other posts from Stack Overflow
or by Goober
Published on 2010-02-08T10:16:11Z
Indexed on
2010/05/17
2:40 UTC
Read the original article
Hit count: 415
Scenario
I have a stored procedure written in T-Sql that I use to insert data into a table as XML. Since the data gets updated regularly, I want the rows to be updated if they already exist (Aside from when the application is first run, they will always exist).
Question
Below is the code of my Insert Sproc, however I cannot seem to workout the Update side of the stored procedure & would appreciate some help.
CODE
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[INS_Curve]
(
@Curve varchar(MAX)
)
AS
DECLARE @handle int
exec sp_xml_preparedocument @handle OUTPUT, @Curve
INSERT INTO CurveDB..tblCurve(LoadID,BusinessDate, Factor)
SELECT LoadID,BusinessDate, Factor
FROM OPENXML(@handle, 'NewDataSet/Table1',2)
WITH(
LoadID int,
BusinessDate DateTime,
Factor float
)
exec sp_xml_removedocument @handle
© Stack Overflow or respective owner