ALTER PROCEDURE GetSingersGenere
(@SingerData ntext)
AS
BEGIN
DECLARE @hDoc int
exec sp_xml_preparedocument @hDoc OUTPUT,@SingerData
IF OBject_id('SingerTable') IS NOT NULL
BEGIN
DROP TABLE SingerTable
END
CREATE TABLE SingerTable
(
SingerName varchar(200)
)
INSERT INTO SingerTable
(
SingerName
)
SELECT * FROM OpenXML (@hDoc,'/Singers/Singer')
WITH (SingerName varchar(200)) XMLSinger
SELECT * FROM SingerTable
END
我现在的执行方式是这样的:
EXEC GetSingersGenere
'<Singers>
<Singer>
Joe
</Singer>
<Singer>
ACDC
</Singer>
</Singers>'
我看到 NULL 被插入到了表中。有人可以指出错误吗?
SELECT * FROM OpenXML (@hDoc,'/Singers/Singer/text()')
吗?你的XPath选择元素...也许除非你明确要求它,否则选择不会将它们转换为它们的文本内容。 - LarsH