SQL如何根据传入的参数来判断是否执行where条件 存储过程

begin
select [reimbursement_id] = a.reimbursement_id
,[formCode] = a.formCode
,[reimbursement_title] = a.reimbursement_title
,[reimbursement_company_name] = c.EipCompanyShortName
,[VATPriceAmount] = a.VATPriceAmount
,[VATTaxAmount] = a.VATTaxAmount
,[last_modify_time]=a.last_modify_time
,[IsInclueSale] = a.IsInclueSale
,[total_money] = a.total_money
,[SaleTaxRate] = a.SaleTaxRate
,[SaleTaxAmount] = a.SaleTaxAmount
,[basic_data_value] = ISNULL(b.basic_data_value,'未指定')
,ROW_NUMBER() over(order by formCode) as RowIndex

    into #NoPagedDataSet1
    from [Finance].[dbo].[finance_reimbursement] a WITH ( NOLOCK )
    INNER JOIN dbo.finance_companyMapping c WITH ( NOLOCK )
    ON a.reimbursement_company_code = c.EipCode
    LEFT JOIN dbo.finance_basic_data b WITH ( NOLOCK )
    ON a.[SaleTaxRate] = b.basic_data_id and b.basic_data_type_id=64 
    where a.reimbursement_type = 2
    and formCode like '%'+ISNULL(@FormCode,'')+'%'
    and reimbursement_title like '%'+ISNULL(@FormTitle,'')+'%'
    and a.last_modify_time between @PassedDateFrom and @PassedDateTo 
    and a.IsInclueSale = @IsInclueSale      @IsInclueSale怎么为空时不执行
    and a.reimbursement_company_code = @Company_Code     @Company_Code怎么为空时不执行

    order by [reimbursement_id] desc
    select *,RowIndex from #NoPagedDataSet1
    where 

    RowIndex > ((@CurrentPage - 1) * @PageSize) And RowIndex <=(@CurrentPage * @PageSize)

    SET @TotalCount = (SELECT COUNT(*) AS TotalCount FROM #NoPagedDataSet1)

    drop table #NoPagedDataSet1

end

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐