请大家给看一下

ITFWJ 2005-12-10 04:06:21
基础差,帮一下忙解释下面的流程。要学好SQL能做到在其他软件提供的二次开发中取出自己的报表,学什么类的资料最好,最快。
if IsNULL(@strInvCCode1,'')<>'' and IsNULL(@strInvCCode2,'')<>''
Begin
If @strInvCCode1 <= @strInvCCode2
Begin
Set @sExtInvFilter = ' And (LEFT(Inventoryclass.cInVCCode,Len(' + @strInvCCode1 + ')) Between '''
+ @strInvCCode1 +''' and ''' + @strInvCCode2 +''')'
--Select @sExtInvFilter --Debug
End
Else If @strInvCCode1 > @strInvCCode2
Begin
Set @sExtInvFilter = ' And (LEFT(Inventoryclass.cInVCCode,Len(' + @strInvCCode1 + ')) Between '''
+ @strInvCCode2 +''' and ''' + @strInvCCode1 +''')'
--Select @sExtInvFilter --Debug
End
End

else if IsNULL(@strInvCCode1,'')<>'' and IsNULL(@strInvCCode2,'')=''
Set @sExtInvFilter =' And (InventoryClass.cInvCCode Like ''' +@strInvCCode1 +'%'')'
else if IsNULL(@strInvCCode1,'')='' and IsNULL(@strInvCCode2,'')<>''
Set @sExtInvFilter =' And (InventoryClass.cInvCCode Like ''' +@strInvCCode2 +'%'')'
...全文
68 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
mislrb 2005-12-10
  • 打赏
  • 举报
回复
这是一段根据@strInvCCode1 和 @strInvCCode2 两个变量得到数据过滤条件的SQL语句,
大致注解如下:

IF @strInvCCode1 和 @strInvCCode2 两个都不为NULL 则进一步做判断
begin
if @strInvCCode1 <= @strInvCCode2
得到 between 1 and 2
if @strInvCCode1 > @strInvCCode2
得到 between 2 and 1
end
elseif @strInvCCode1 不为空,@strInvCCode2为空
得到 LIKE 1
elseif @strInvCCode1 为空,@strInvCCode2不为空
得到 LIKE 2
lsqkeke 2005-12-10
  • 打赏
  • 举报
回复
if IsNULL(@strInvCCode1,'')<>'' and IsNULL(@strInvCCode2,'')<>'' --都不为空值的情况
Begin
--根据大小关系,确定 between..and..中两个参数的位置
If @strInvCCode1 <= @strInvCCode2
Begin
Set @sExtInvFilter = ' And (LEFT(Inventoryclass.cInVCCode,Len(' + @strInvCCode1 + ')) Between '''
+ @strInvCCode1 +''' and ''' + @strInvCCode2 +''')'
--Select @sExtInvFilter --Debug
End
Else If @strInvCCode1 > @strInvCCode2
Begin
Set @sExtInvFilter = ' And (LEFT(Inventoryclass.cInVCCode,Len(' + @strInvCCode1 + ')) Between '''
+ @strInvCCode2 +''' and ''' + @strInvCCode1 +''')'
--Select @sExtInvFilter --Debug
End
End
--接着第一个IF 语句的ELSE,当其中一个为空值时,SQL的连接组成情况
else if IsNULL(@strInvCCode1,'')<>'' and IsNULL(@strInvCCode2,'')=''
Set @sExtInvFilter =' And (InventoryClass.cInvCCode Like ''' +@strInvCCode1 +'%'')'
else if IsNULL(@strInvCCode1,'')='' and IsNULL(@strInvCCode2,'')<>''
Set @sExtInvFilter =' And (InventoryClass.cInvCCode Like ''' +@strInvCCode2 +'%'')'

lsqkeke 2005-12-10
  • 打赏
  • 举报
回复
上面这段是判断传递的参数 @strInvCCode1 和 @strInvCCode2 是否为空,以及都不为
空的情况下,某个为空等条件下组拼 SQL语句的代码
应该是写在存储过程里边的!

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧