SQLTeam.com | Weblogs | Forums

I need to get only those rows which has more than 4 characters after space

tsql
sql2008r2

#1

I was able to get the rows which has space but not sure how to get the columns which has four or more characters after space.

SELECT LAST_NAME
FROM CUSTOMER
WHERE (RECORD_TYPE = 'i') AND (CUSTOMER_STATUS_CODE = 'ACTIVE')
AND (LAST_NAME LIKE '% %') AND (NOT (NAME_CREDENTIALS IS NULL))

In above image, After space there are rows has more than 4 characters after space. I need to get only those rows which has more than 4 characters after space.


#2

Try:
(LAST_NAME LIKE '% %[^ ][^ ][^ ][^ ]%')


#3

try

len(LAST_NAME ) -charindex(' ',LAST_NAME ) = 4


#4

Thank you Scott


#5

What if I want to get 4 or less characters after space.


#6

If you want at least one non-space, then do this:

(LAST_NAME LIKE '% %[^ ]%')