I have a field that returns the value as xxx-xxx-xxx-xxxxx-xx-x. How do i extract the 10th character from that code.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
select substring('xxx-xxx-xxx-xxxxx-xx-x', 10, 1)
The documentation for the function on MSDN is here.
The SQL Fiddle demo is here (with different letters so you can clearly see which letter is extracted).
回答2:
Use substring
function
select substring('xxx-xxx-xax-xxxxx-xx-x', 10, 1)
回答3:
you can use SUBSTRING
, in your case use...
SELECT SUBSTRING(field, 10, 1)
field being the one that returns the value.
回答4:
declare @x varchar(20) = 'xxx-xxx-xxx-xxxxx-xx-x'
select SUBSTRING(@x,10,CHARINDEX('-',@x)-4 )