Reputation:
How can I get the character at position 4 in a field?
e.g.
field contents = "hello"
I want to return the value of position 2 = "l"
Upvotes: 41
Views: 121062
Reputation: 166386
In SQL Server you can use SUBSTRING
SELECT SUBSTRING('hello', 3, 1)
Take care: index is 1-based.
Upvotes: 61
Reputation: 21
following Query will search from specific index for char and will return result
select * from tbPatientMaster
where SUBSTRING (fname,CHARINDEX ('.',fname,0)+1,LEN (fname)) like 'a%'
Upvotes: 2
Reputation: 21505
In Oracle, use SUBSTR
Syntax is SUBSTR(<string to parse>,<start position>,(<length>))
- i.e.
SELECT SUBSTR('hello',3,1)
Start position and length are one-, not zero-based. Zero is accepted, but will be interpreted as 1.
Upvotes: 11