2014-01-22 67 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