对于像下面这样的表模式
CREATE TABLE [dbo].[Employee](
[EmployeeId] [uniqueidentifier] NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[Location] [nvarchar](50) NOT NULL,
[Skills] [xml] NOT NULL,
[Projects] [nvarchar](400) NULL,
CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED
将数据插入表时,我只想插入子标签,<SkillSet>
但似乎<SkillSet>
与它的子元素一起插入到 Skill xml 列中。
declare @doc NVARCHAR(MAX)
declare @idoc INT
select @doc = '<Request Type="InsertEmployee" CRUD="C">
<Employee>
<EmployeeId>1</EmployeeId>
<Name>Deeptechtons</Name>
<Location>USA</Location>
<SkillSet>
<Skill>C#</Skill>
<Skill>SQL Server 2005</Skill>
<Skill>ASP.net</Skill>
</SkillSet>
<Projects>
<Project>LowBin</Project>
<Project>Maskin</Project>
</Projects>
</Employee>
</Request>'
exec sp_xml_preparedocument @idoc output,@doc
insert into Employee (
EmployeeId
,[Name]
,Location
,Skills,
Projects
)
SELECT NEWID()
,[Name]
,Location
,Skills
,Projects
FROM OPENXML(@idoc,'Request/Employee',2)
WITH
(
[Name] NVARCHAR(50)
,Location NVARCHAR(50)
,Skills XML 'SkillSet'
,Projects NVARCHAR(400)
)
exec sp_xml_removedocument @idoc
问题
如何仅插入子元素
<Skillset>
而不是整个标签及其子元素。我
Projects
也希望插入与之前相同的内容,但只Lowbin
插入第一个 Project 标记的内容。你能更正我的代码吗?