TSQL如何在xml列中选择具有技能的员工 [英] TSQL How to select employee with skills in xml column
本文介绍了TSQL如何在xml列中选择具有技能的员工的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在如下表模式中
CREATE TABLE [dbo].[Employee](
[EmployeeId] [uniqueidentifier] NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[Location] [nvarchar](50) NOT NULL,
[Skills] [xml] NOT NULL
CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED
假设
Skills
列中保存的 xml 如下所示,我如何让员工拥有C#
(不区分大小写)编程技能.How would i get Employees having
C#
(case insensitive) programming skills assuming the xml saved in theSkills
columns is as below.你能对其他函数的建议能帮助我过滤、排序时使用xml数据类型列
Could you advice on other functions would help me filter, sort when using xml data type columns
C# ASP.NET VB.NET 推荐答案
比较区分大小写,因此您需要同时与 c# 和 C# 进行比较.在 SQL Server 2008 中,您可以使用 大写.
The comparison is case sensitive so you need to compare against both c# and C#. In SQL Server 2008 you can use upper-case.
declare @T table ( ID int identity, Skills XML ) insert into @T values ('<Skills><Skill>C#</Skill><Skill>ASP.NET</Skill><Skill>VB.NET</Skill></Skills>') insert into @T values ('<Skills><Skill>CB.NET</Skill><Skill>ASP.NET</Skill><Skill>c#</Skill></Skills>') insert into @T values ('<Skills><Skill>F#</Skill><Skill>ASP.NET</Skill><Skill>VB.NET</Skill></Skills>') select ID from @T where Skills.exist('/Skills/Skill[contains(., "C#") or contains(., "c#")]') = 1
结果:
ID ----------- 1 2
更新:
这也行.
select T.ID from @T as T cross apply T.Skills.nodes('/Skills/Skill') as X(N) where X.N.value('.', 'nvarchar(50)') like '%C#%'
这篇关于TSQL如何在xml列中选择具有技能的员工的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文