日期:2014-05-18  浏览次数:20670 次

菜鸟问:存储过程的问题。
set @where = 
' where SL.CrtDate between '''+@BeginDate+''' and '''+@EndDate+'''
and (S.name like '''+@Store+''' or '+@Store+' is null)
and (SL.ListFlag = '''+@ListFlag+''' or '+@ListFlag+' is null)
and (SL.ListNo like '''+@ListNo+''' or '+@ListNo+' is null)
and (SL.HostNo like '''+@HostNo+''' or '+@HostNo+' is null)
and (UT.username like '''+@OptName+''' or '+@OptName+' is null)
and (E.Name like '''+@SalesName+''' or '+@SalesName+' is null)
'

调用时老提示关键字 'is' 附近有语法错误。


------解决方案--------------------
and (S.name like '''+@Store+''' or '+@Store+' is null)
and (SL.ListFlag = '''+@ListFlag+''' or '+@ListFlag+' is null)
and (SL.ListNo like '''+@ListNo+''' or '+@ListNo+' is null)
and (SL.HostNo like '''+@HostNo+''' or '+@HostNo+' is null)
and (UT.username like '''+@OptName+''' or '+@OptName+' is null)
and (E.Name like '''+@SalesName+''' or '+@SalesName+' is null)

这么多个,先只写一个试试.

把拼接生成的语句,打印到界面上,单独复制运行拼接出来语句.再找错误就好办了.
------解决方案--------------------
S.name like '''+@Store+''' or S.name is null

或许,里面应该如此.
------解决方案--------------------
"or '+@ListNo+' is null)“
ListNo是整型或者长整型吧?如果是这样,就不能在后面加上is null,因为整型或者长整型是值类型,即使没有赋值,也有个默认值0,你试试把它改成<>0吧!
------解决方案--------------------
探讨

and (S.name like '''+@Store+''' or '+@Store+' is null)
and (SL.ListFlag = '''+@ListFlag+''' or '+@ListFlag+' is null)
and (SL.ListNo like '''+@ListNo+''' or '+@ListNo+' is null)
and (SL.HostNo lik……

------解决方案--------------------
语法可以说过去,请把变量类型放出来,没类型不好判断
------解决方案--------------------
探讨

哪位高手帮帮忙啊?急啊。。。

------解决方案--------------------
and (S.name like '''+@Store+''' or '''+@Store+''' is null)
------解决方案--------------------
用print @where 输出sql调试一下
------解决方案--------------------
你那是双引号 还是 3个单引号?