hungrykoala
hungrykoala

Reputation: 1083

How to remove some texts from a field during a select query?

I have a field in my table that contains this value:

#3 text For string# 1
#4 Payment For Inv# 5

What I want to do here is to only display "1 and 5" after a select query, and the problem is that #n is not limited to a single digit only thus, I cannot use SUBSTRING.

Any ideas on how to proceed with this?

Upvotes: 1

Views: 46

Answers (2)

sagi
sagi

Reputation: 40481

If its 1 digit number, always on the right of the string, use RIGHT() :

SELECT RIGHT(t.YourColumn) FROM YourTable t

Upvotes: 1

Saty
Saty

Reputation: 22532

As 1 and 5 comes at last position of string so you get the last character of string as

SELECT SUBSTRING_INDEX(YOUR_COLUMN, ' ', -1) FROM YOUR_TABLE

Upvotes: 1

Related Questions