Select * from vwOutHouseDsp
where iDocStatus<=100 and dDocDate>=@tdBDate and dDocDate<=@tdEDate
and (cDocType='销售发货' or cDocType='销售退货')
and WhSysCode=case when @tcWhSysCode='' then WhSysCode else @tcWhSysCode End
and ISysCode=case when @tcISysCode='' then ISysCode else @tcISysCode End
and IBSysCode=case when @tcIBSysCode='' then IBSysCode else @tcIBSysCode 以上这句在WHERE上使用CASE后查速度就变得很慢了,如果把
and WhSysCode=case when @tcWhSysCode='' then WhSysCode else @tcWhSysCode End
and ISysCode=case when @tcISysCode='' then ISysCode else @tcISysCode End
and IBSysCode=case when @tcIBSysCode='' then IBSysCode else @tcIBSysCode
这几句去掉,速度就正常了,怎么会这样呢?
另外,如果不用CASE,这种情况的条件查询怎样解决比较好呢?
where iDocStatus<=100 and dDocDate>=@tdBDate and dDocDate<=@tdEDate
and (cDocType='销售发货' or cDocType='销售退货')
and WhSysCode=case when @tcWhSysCode='' then WhSysCode else @tcWhSysCode End
and ISysCode=case when @tcISysCode='' then ISysCode else @tcISysCode End
and IBSysCode=case when @tcIBSysCode='' then IBSysCode else @tcIBSysCode 以上这句在WHERE上使用CASE后查速度就变得很慢了,如果把
and WhSysCode=case when @tcWhSysCode='' then WhSysCode else @tcWhSysCode End
and ISysCode=case when @tcISysCode='' then ISysCode else @tcISysCode End
and IBSysCode=case when @tcIBSysCode='' then IBSysCode else @tcIBSysCode
这几句去掉,速度就正常了,怎么会这样呢?
另外,如果不用CASE,这种情况的条件查询怎样解决比较好呢?
WhSysCode=iif(@tcWhSysCode='',WhSysCode,@tcWhSysCode)
and ISysCode=iif(@tcISysCode='',ISysCode,@tcISysCode)
and IBSysCode=iif(@tcIBSysCode='',IBSysCode,@tcIBSysCode )
@tcWhSysCode,@tcISysCode,@tcIBSysCode 默认设成null
create procedure protest
@tcWhSysCode int =null,
@tcISysCode int =null,
@tcIBSysCode int =null
as
Select * from vwOutHouseDsp
where iDocStatus<=100 and dDocDate>=@tdBDate and dDocDate<=@tdEDate
and (cDocType='销售发货' or cDocType='销售退货')
and WhSysCode=isnull(@tcWhSysCode,WhSysCode)
and ISysCode=isnull(@tcISysCode,ISysCode)
and IBSysCode=isnull(@tcIBSysCode,IBSysCode)