sql怎么取某個字符串最后一次出現的位置后面的字符串


 

如:

'ab-cd-ef-gh'

現在要取到,第三個'-'后面的gh

 

1
2
3
4
declare @s varchar(100);
set @s = 'ab-cd-ef-gh';
 
select right(@s, charindex('-',reverse(@s))-1)

 

declare  @str  char (20)
set  @str= 'ab-cd-ef-gh'
 
select  stuff(@str,1,len(@str)-charindex( '-' ,reverse(rtrim(@str)))+1, '' as  result
 
select  substring (@str,len(@str)-charindex( '-' ,reverse(rtrim(@str)))+2,charindex( '-' ,reverse(rtrim(@str)))-1)  as  result
 
select  reverse( left (reverse(@str),charindex( '-' ,reverse(@str))-1))  as  result
 
select  right (@str,charindex( '-' ,reverse(@str))-1)  as  result
 
 
 
 
 
 
 
 
 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM