使用输入参数查询XML

时间:2014-01-22 21:38:02

标签: sql sql-server xml

目前我正在使用此查询获取结果:

Select *
From Staff 
Where StaInsurance.exist('/COLInsuranceCompany/DOInsuranceCompany[Name/text()[. = "Apollo Life Assurance"]]') = 1  

如何在查询中使用输入参数而不是硬编码字符串,下面不起作用:

declare @IInsurance nvarchar(200)
set @IInsurance = 'Apollo Life Assurance'

Select *
From Staff 
Where StaInsurance.exist('(/COLInsuranceCompany/DOInsuranceCompany/Name[id=(sql:variable("@IInsurance"))])[1]') = 1

1 个答案:

答案 0 :(得分:1)

declare @IInsurance nvarchar(200)
set @IInsurance = 'Apollo Life Assurance'

Select *
From Staff 
Where StaInsurance.exist('/COLInsuranceCompany/DOInsuranceCompany/Name[text() = sql:variable("@IInsurance")]') = 1