帆软用户A45YkexW7S(提问者) 回复 snrtuemcselect *,\'月\' as tjlb1,count(distinct substring(dm,1,4)) as 数
into #sl
from BK (nolock)
where substring(cyrq,1,7)=\'${tjrq}\'+\'-\'+\'${tjsj}\'
union
select *,\'季\' as tjlb1,count(distinct substring(dm,1,4)) as 数
from BK (nolock)
where case when substring(cyrq,6,2) in (\'01\',\'02\',\'03\') then substring(cyrq,1,4)+\'一季度\' when substring(cyrq,6,2) in (\'04\',\'05\',\'06\') then substring(cyrq,1,4)+\'二季度\' when substring(cyrq,6,2) in (\'07\',\'08\',\'09\') then substring(cyrq,1,4)+\'三季度\' when substring(cyrq,6,2) in (\'10\',\'11\',\'12\') then substring(cyrq,1,4)+\'四季度\' end =\'${tjrq}\'+\'${tjsj}\'
union
select *,\'年\' as tjlb1,count(distinct substring(dm,1,4)) as 数
from BK (nolock)
where substring(cyrq,1,4) =\'${tjrq}\'
order by cyrq
select * from #sl (nolock)
where tjlb1=\'${tjlb}\'
帆软用户A45YkexW7S(提问者)select *,\'月\' as tjlb1,count(distinct substring(dm,1,4)) as 数
into #sl
from BK (nolock)
where substring(cyrq,1,7)=\'${tjrq}\'+\'-\'+\'${tjsj}\'
union
select *,\'季\' as tjlb1,count(distinct substring(dm,1,4)) as 数
from BK (nolock)
where case when substring(cyrq,6,2) in (\'01\',\'02\',\'03\') then substring(cyrq,1,4)+\'一季度\' when substring(cyrq,6,2) in (\'04\',\'05\',\'06\') then substring(cyrq,1,4)+\'二季度\' when substring(cyrq,6,2) in (\'07\',\'08\',\'09\') then substring(cyrq,1,4)+\'三季度\' when substring(cyrq,6,2) in (\'10\',\'11\',\'12\') then substring(cyrq,1,4)+\'四季度\' end =\'${tjrq}\'+\'${tjsj}\'
union
select *,\'年\' as tjlb1,count(distinct substring(dm,1,4)) as 数
from BK (nolock)
where substring(cyrq,1,4) =\'${tjrq}\'
order by cyrq
select * from #sl (nolock)
where tjlb1=\'${tjlb}\'
帆软用户A45YkexW7S(提问者)select *,\'月\' as tjlb1,count(distinct substring(dm,1,4)) as 数
into #sl
from BK (nolock)
where substring(cyrq,1,7)=\'${tjrq}\'+\'-\'+\'${tjsj}\'
union
select *,\'季\' as tjlb1,count(distinct substring(dm,1,4)) as 数
from BK (nolock)
where case when substring(cyrq,6,2) in (\'01\',\'02\',\'03\') then substring(cyrq,1,4)+\'一季度\' when substring(cyrq,6,2) in (\'04\',\'05\',\'06\') then substring(cyrq,1,4)+\'二季度\' when substring(cyrq,6,2) in (\'07\',\'08\',\'09\') then substring(cyrq,1,4)+\'三季度\' when substring(cyrq,6,2) in (\'10\',\'11\',\'12\') then substring(cyrq,1,4)+\'四季度\' end =\'${tjrq}\'+\'${tjsj}\'
union
select *,\'年\' as tjlb1,count(distinct substring(dm,1,4)) as 数
from BK (nolock)
where substring(cyrq,1,4) =\'${tjrq}\'
order by cyrq
select * from #sl (nolock)
where tjlb1=\'${tjlb}\'