问题描述
- 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 RowIndexinto #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
时间: 2024-12-03 01:04:11