【发布时间】:2011-08-23 18:56:29
【问题描述】:
我正在尝试编写一个存储过程,在其中我从 XML 字符串中插入一些内容。 这是为了避免从循环内部进行大量存储过程调用。
这是我到目前为止得到的,但它给了我错误:
消息 207,级别 16,状态 1,过程 newsMapper_prc,第 22 行
列名“标题”无效。
消息 207,级别 16,状态 1,过程 newsMapper_prc,第 22 行
列名“故事”无效。
消息 207,级别 16,状态 1,过程 newsMapper_prc,第 25 行
列名“实体”无效。
消息 207,级别 16,状态 1,过程 newsMapper_prc,第 27 行
列名“实体”无效。
实在想不通,不胜感激
<newsfile>
<headline>THIS IS A NEWS HEADLINE</headline>
<story>THIS IS A NEWS STORY</story>
<entity> 1234</entity>
<entity>1111</entity>
<entity>2222</entity>
</newsfile>
存储过程代码:
CREATE PROCEDURE newsMapper_prc
-- Add the parameters for the stored procedure here
(@xmlString xml)
AS
declare @criteriaTable table (criterianame varchar(100), parm varchar(MAX))
insert into @criteriaTable
Select
criteriaValues.parm.value('../@type','varchar(MAX)'),
criteriaValues.parm.value('.','varchar(MAX)')
from @xmlString.nodes('/newsfile/headline') as headline(parm),
@xmlString.nodes('/newsfile/headline/story') as story(parm),
@xmlString.nodes('/newsfile/headline/story/entity') as entity(parm)
insert into News (newsHeadline, newsStory, newsDate) values ((select headline from @criteriaTable),(select story from @criteriaTable), GETDATE())
declare @newsID int
SET @newsID = scope_identity()
while exists (select entity from @criteriaTable)
BEGIN
insert into NewsEntities(newsID,entityID) values (@newsID,( Select entity from @criteriaTable))
END
【问题讨论】:
-
我想这应该是 SQL Server 吧?哪个版本?
标签: sql sql-server xml stored-procedures