Avatar of pzozulka
pzozulka
 asked on

SQL string sensitive search

declare @reason varchar(4000)

set @reason = 'Test, Reason'

select *
from Transactions t
where t.UserReason in (select item from dbo.CreateStringTable(@reason))

Open in new window


I have a stored procedure which accepts @reason as an incoming string parameter, but for the purposes of this post, I declred @reason manually, and assigned it some test values. In the stored procedure, we use a function "CreateStringTable", which accepts a string of comma separated values, and returns them as a column in a table.

To avoid confusion, the query above can be seen as:
select *
from Transactions t
where t.UserReason in (select columnA from TableA)

Open in new window



How do I do a case-sensitive search of this? In other words, if columnA only contains the word 'Test', and t.UserReason contains only the word 'test', no records should be returned.
Microsoft SQL ServerMicrosoft SQL Server 2008

Avatar of undefined
Last Comment
pzozulka

8/22/2022 - Mon
Éric Moreau

you can use a Case-Sensitive collation:
Select * from a_table where attribute = 'k' COLLATE Latin1_General_CS_AS 

Open in new window

pzozulka

ASKER
I get an error message: Incorrect syntax near the keyword 'COLLATE'. Query below:
Select * from a_table 
where attribute in (select columnA from TableA) COLLATE Latin1_General_CS_AS 

Open in new window

ASKER CERTIFIED SOLUTION
Arifhusen Ansari

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
pzozulka

ASKER
Thanks Arif, that worked out great.
Your help has saved me hundreds of hours of internet surfing.
fblack61