在XML PATH查询中使用多个like语句的最佳方法

时间:2016-11-07 17:57:40

标签: tsql for-xml-path

当我使用"或"运算符(Secretary_Job_Title like '%Secretary%' or Secretary_Job_Title like '%Assistant%')我返回的值太多了。

如何在以下查询中最好地使用Like语句为秘书和助理?提前致谢!!

 SELECT STUFF((SELECT ';' + secretary
          FROM   [HandshakeProd].[dbo].[sp_attysecrel]
          WHERE  attorney = 'HC\' + Rtrim(p.EMPLOYEE_CODE)
                 AND secretary_job_title LIKE '%Secretary%'
          FOR XML PATH('')), 1, 1, '') AS [Assistants]  

1 个答案:

答案 0 :(得分:0)

也许这就是你想要的?

SELECT STUFF((SELECT ';' + secretary
          FROM   [HandshakeProd].[dbo].[sp_attysecrel]
          WHERE  attorney = 'HC\' + Rtrim(p.EMPLOYEE_CODE)
                 AND (secretary_job_title LIKE '%Secretary%' OR secretary_job_title LIKE '%Assistant%')
          FOR XML PATH('')), 1, 1, '') AS [Assistants]