Find records that end with special characters

General
Enthusiast

Find records that end with special characters

Hello folks,

 

I have a question. I have a records where ID ends with a special character '-'. I am trying to find all the records athat end with this. So I executed a query as below.

 

Sel * from Tablename where ID like '%-'

But is not returning any records. But i am sure there are records like that. Can you help me if i am going wrong anywhere.

 

Thanks in advance.


Accepted Solutions
Highlighted
Teradata Employee

Re: Find records that end with special characters

Add space to end of column
(Id || ' ') like '%- %'
1 ACCEPTED SOLUTION
3 REPLIES
Highlighted
Teradata Employee

Re: Find records that end with special characters

Add space to end of column
(Id || ' ') like '%- %'
Enthusiast

Re: Find records that end with special characters

Thanks David. It worked.

Junior Contributor

Re: Find records that end with special characters

This column is probably a CHAR(n) and your existing LIKE does find not match any row with a trailing space.

While @David_Roth's works it might return false positives like 'abc- abc' it's better to trim the trailing spaces instead:

where trim(trailing from ID) like '%-'