user7512602
user7512602

Reputation:

Filtering records based on last 4/5 characters of VARCHAR

I have a VARCHAR column that contains an integer followed by a forward slash and a four digit integer.

Example Data:

82/2015
126/2017
5763/2017

I'm trying to retrieve only the records that end in 2017.

126/2017
5763/2017

I'm assuming I need to use the forward slash to split the string and then perform a comparison? Or maybe I could simply perform a comparison against the last 4/5 characters? Does SQL contain a function that can do either of these for me?

Upvotes: 0

Views: 322

Answers (2)

Derrick Moeller
Derrick Moeller

Reputation: 4950

You can use RIGHT to do this.

SELECT *
FROM YourTable
WHERE RIGHT(SomeDate, 4) = '2017'

Upvotes: 1

Gordon Linoff
Gordon Linoff

Reputation: 1269693

Use like:

where col like '%/2017'

Upvotes: 2

Related Questions