0
declare @schoolName varchar(max) = 'children's Garden'

select * from schools where Schoolname like @schoolName+'%'

This is my SQL query. When I store a string with an apostrophe there is error. How can I overcome this?

The variable @schoolName is coming from the code.

Dale K
  • 21,987
  • 13
  • 41
  • 69

1 Answers1

4

Use double apostrophes to make it valid SQL String :

declare @schoolName varchar(max) = 'children''s Garden'

select s.* 
from schools s 
where s.Schoolname like @schoolName + '%'
Yogesh Sharma
  • 49,081
  • 5
  • 23
  • 49