2015-10-01 10 views
0
**speciality** 
---name 
--name 
-name 

因此它不會給我不同的值,由於空間( - )如何使用LTRIM我想補充LTRIM這個查詢,使我得到了數據室內用LTRIM也不同

select distinct split.a.value('.','varchar(100)')as string from (select cast ('<M>' + replace(speciality, ',', '</M><M>') + '</M>' as xml) as string from health where type='Doctor' and speciality like '%dentist%') as a cross apply String.nodes ('/M') as split(a) 
+0

'選擇不同REPLACE( ' 'split.a.value(' VARCHAR(100) '),'', '') ...''或'選擇不同的REPLACE(split.a.value('。','varchar(100)'),' - ','')' – lad2025

+0

感謝它的作品,但m使用ltrim,適合我,謝謝很多 –

回答

0

使用REPLACE

DEMO

select distinct REPLACE(split.a.value('.','varchar(100)'), '-', '') as string 
from (select cast ('<M>' + replace(speciality, ',', '</M><M>') + '</M>' as xml) as string 
     from health 
     where type='Doctor' 
     and speciality like '%dentist%') as a 
cross apply String.nodes ('/M') as split(a) 

,或者如果你的數據是:

**speciality** 
    name 
    name 
name 

使用只是LTRIM

select distinct LTRIM(split.a.value('.','varchar(100)')) as string 
from (select cast ('<M>' + replace(speciality, ',', '</M><M>') + '</M>' as xml) as string 
      from health 
      where type='Doctor' 
      and speciality like '%dentist%') as a 
cross apply String.nodes ('/M') as split(a) 
+0

@Niteshkumar如果這個答案有幫助,請考慮標記接受它http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work :) – lad2025