Reputation:
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
Reputation: 4950
You can use RIGHT
to do this.
SELECT *
FROM YourTable
WHERE RIGHT(SomeDate, 4) = '2017'
Upvotes: 1