David Brierton
David Brierton

Reputation: 7397

T-SQL query fails when data is lowercase because database holds it in capitalization

In my database all the data is capitalized, for example Last Name (BRIERTON). When I run my query in lowercase like (brierton), it will not find it. Is it possible to put something in the query to search both capital or lowercase so that it does not think it does not exist for [pye_nlast] AS "Name Last"?

SELECT 
    [pye_nlast] AS "Name Last",
    [pye_nfirst] AS "Name First",
    [EmployeeTC_No] AS "Employee TC #",
    [EmploymentType] AS "Employment Type",
    [RetentionCode] AS "GS #"
FROM 
    [OnBaseWorking].[dbo].[Employees]
WHERE
    EmployeeTC_No != 'Not Assigned'
    AND pye_nlast = '@primary'

Any help with this would be greatly appreciated!

Upvotes: 0

Views: 188

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269953

You can just force lower case:

lower(pye_nlast) = lower(@primary)

I'm not sure why you are enclosing @primary in single quotes. That is suspicious.

Or, if the data really is all in upper case:

pye_nlast = upper(@primary)

Upvotes: 1

Related Questions