請檢查該樣品SP
你需要爲每行同樣喜歡下面的格式創建XML和給SQL ..
一些修改,按照您的要求,可以解決你的問題..
/**************************************************************
EXEC wa_TempInsert '<SampleXML>
<tblRow><Id>3</Id><Code>11</Code><Description>Leptospiral infect NEC</Description></tblRow>
<tblRow><Id>3</Id><Code>22</Code><Description>Leptospiral infect NEC</Description></tblRow>
<tblRow><Id>3</Id><Code>33</Code><Description>Leptospiral infect NEC</Description></tblRow>
<tblRow><Id>3</Id><Code>44</Code><Description>Leptospiral infect NEC</Description></tblRow>
<tblRow><Id>3</Id><Code>55</Code><Description>Leptospiral infect NEC</Description></tblRow>
</SampleXML>'
*/
CREATE PROCEDURE wa_TempInsert
(
@XML NVARCHAR(MAX)
)
AS
SET NOCOUNT ON
BEGIN
DECLARE @Id INT
DECLARE @MyXML XML
SET @MyXML = @XML
IF OBJECT_ID('tempdb..#TempXMLTable') IS NOT NULL
DROP TABLE #TempICD
SELECT * INTO #TempICD
FROM (
SELECT
Parse.value('(Id)[1]', 'INT') AS 'Id',
Parse.value('(Code)[1]', 'Varchar(100)') AS 'Code',
Parse.value('(Description)[1]', 'varchar(1000)') AS 'Description'
FROM
@MyXML.nodes('/SampleXML/tblRow') AS TempData(Parse)
) AS tbl
INSERT INTO Table (Code,[Description],Id)
SELECT DISTINCT Code,[Description],Id FROM #TempXMLTable
END
END
是100條記錄只在一張桌子上插入..每次..? – 2013-05-07 12:14:11
是的,但有時每個插入超過100個 – 2013-05-07 12:20:49
沒有深入的存儲過程或表結構,我覺得這是非常嚴重的結構。 40插入查詢,它真的很糟糕。向創造它的人致敬。對不起,如果是你。 – 2013-05-07 12:50:19