-1
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
  • 25,246
  • 15
  • 42
  • 71
ReaL_HyDRA
  • 314
  • 1
  • 18

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,870
  • 5
  • 26
  • 52