December 8, 2011 at 9:27 am
I have a simple SELECT STATEMENT which is not returning data. I am attempting to find all entries ending in "LA"
SELECT * FROM "Table"
WHERE "Column" LIKE '%LA'
GO
This statement returns no values. If I use '%LA%' I do have data returned but it includes thousand of rows which are not needed. Any idea why this simple statement is not returning data?
Platform is SQL Server 2008
December 8, 2011 at 9:28 am
if the column you are searching is a char and not varchar, it might not truely end in LA;
try WHERE RTRIM(ColumnName) LIKE '%LA' instead
Lowell
December 8, 2011 at 9:36 am
Lowell,
Adding rtrim before the column name worked perfectly. The column is actually nchar. Can you tell me what this data type adds to the end of data which requires a trim to be used?
December 8, 2011 at 9:44 am
Spaces, like char. They're only a factor when using LIKE. = ignores trailing spaces, LIKE doesn't (it is documented)
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply