declare @paging as varchar(max)
set @paging = 'A'
if @paging is null Or @paging =''
set @paging = 'where ttmo_supp =''tt&MO'''
else
set @paging = 'where ttmo_supp =''tt&MO'' and Name like '+''''+ @paging +'%'''+''
当我执行我的前端代码时,它会抛出错误,指出“tt附近的语法错误不正确”。
答案 0 :(得分:1)
declare @paging as varchar(max)
set @paging = 'A'
if @paging is null Or @paging =''
set @paging = 'where ttmo_supp =''tt&MO'''
else
set @paging = 'where ttmo_supp =''tt&MO'' and Name like '+''''+ @paging +'%'''+''
Select @paging
在变量上的Or之后,您忘记了IF语句中的@符号。
结果
其中ttmo_supp =' tt& MO'和名字一样' A%'
更新了程序
Create Procedure SP_AlphabeticPaging @paging VarChar(Max)
As
Begin
if @paging is null Or @paging =''
set @paging = 'where ttmo_supp =''tt&MO'''
else
set @paging = 'where ttmo_supp =''tt&MO'' and Name like '+''''+ @paging +'%'''+''
Select @paging
End
Go
EXEC SP_AlphabeticPaging 'A'
-- Result
-- where ttmo_supp ='tt&MO' and Name like 'A%'
EXEC SP_AlphabeticPaging ''
-- Result
-- where ttmo_supp ='tt&MO'