2014-01-22 3 views
0

은 현재 내가 결과를 얻으려면이 쿼리를 사용하고 있습니다 : 내가 쿼리에 하드 코딩 된 문자열 대신 입력 매개 변수를 사용할 수있는 방법쿼리 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 
+0

예 : xml 추가 – Backs

답변

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

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

마지막으로 '/'를 제거한 후 고맙습니다. – user2561997

+0

@ user2561997 예, 작은 실수 – Backs