SQL function compare variable to a string

How can I find the correct row when the variable is one character that exists within the field and the field is many characters?

c.gpatypes = OMCG
@gpatypec = 'M'

normally I would find the row with:
select * from c where gpatypes like '%m%'

but the function isn't working with
gpatypes like '%@gpatypec%'
dwiseman3Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
Like '%' + @var + '%'
0
 
Jim HornConnect With a Mentor Microsoft SQL Server Developer, Architect, and AuthorCommented:
^^^ what he said

Also, this will return the character number of the first instance of @gpatypec, so a zero would mean it's not there...

CHARINDEX(c.gpatypes, @gpatypec, 1) > 0
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.