|
Don't simply talk about using dynamic SQL statements. The previous elder brother has already told me and I understand, but I still haven't figured out a way to solve this problem. Please master the following carefully:
There is a stored procedure with 3 input parameters, which are @companname, @startdate, @enddate; representing the company name, start time, end time, the current requirements are:
Each of these three parameters has two states: empty and non-empty. When combined, there are N kinds of results. If you write them one by one, it should be more troublesome. Ask the master to see how to write this stored procedure.
The following is all not empty
——————————————————————————————————
select company id, company name, sum (amount) as total from
(
select * from 1 where request time <@enddate and request time> @startdate
union all
select * from 2 where request time <@enddate and request time> @startdate
) t where approval opinion = 'agree' and company name = @companyname
group by company id, company name order by company id
——————————————————————————————————
The following is all empty
——————————————————————————————————
select company id, company name, sum (amount) as total from
(
select * from 1
union all
select * from 2) t where approval opinion = 'agree' group by company id, company name order by company id
——————————————————————————————————
May also need to pay attention to determine whether the start time and end time are correct, please help me! |
|