SQLThe Escape Character of is: '(single quotes)
Example: Select * From TBL where uyear ='''06'
Note that the single quotation marks of the red background indicate escape characters. If we omit them, the entire statement will fail and the escape characters will not be output. In the preceding example, the actual condition value of uyear is '06, instead of ''06
Why can't it be omitted? If we omit it, the previous sentence becomes: Select * From TBL where uyear =''06'
BecauseSQLThe start and end symbols of the string are enclosed in single quotes?SQLThe interpreter considers the gray background in the statement as a string, and the subsequent statement is obviously an incorrect statement. Of course, an error is reported. To solve the single quotation mark problem of the string, an escape character list is displayed.
SQLThe server has two escape characters :'By default, 'is the boundary character of the string. If' is contained in the string, two 'must be used, and 1st' is the escape character.
Another Escape Character is"
WhenWhen set quoted_identifier off, "is a string boundary, and" must be expressed as two "in the string.
VB: "" <=>"SQLServer 2000: ''' <=>'
SQL Server 2000: "" <=>"
Eg:
Declare @ searchtype nvarchar (50) Declare @ searchstring nvarchar (255) Declare @ searchkey nvarchar (50) Declare @ searchsql nvarchar (2000)
Set @ searchtype = '2' set @ searchkey = 'D'
Set @ searchstring = case @ searchtype when '1' then '1 = 1'When '2' then 'p. projectname like ''' + '%' + @ searchkey + '%' + ''''When '3' then' p. projectcity like ''' + '%' + @ searchkey + '%' + ''' when' 4 'then' C. catename like ''' + '%' + @ searchkey + '%' + '''when' 4 'then' p. projectmanager like ''' + '%' + @ searchkey + '%' + ''' end
Set @ searchsql = N'
Select p. *, datename (year, projectposttime) + '+ '''-''' +' + datename (month, projectposttime) + '+ '''-''' +' + datename (day, projectposttime) '+' As posttime, M. empname, C. catename from proproject as P, mrbaseinf as M, procate c Where p. empid = m. empid and P. cateid = C. cateid and '? ? + @ Searchstring
Print (@ searchsql)
Exec (@ searchsql)