declare
@bdt char(8)
, @edt char(8)
, @sql varchar(8000)
, @col varchar(255)
set @bdt = '20101102'
set @edt = '20101103'
set @sql = ''
set @col = 'val'
select @sql = @sql +
'when ' + @col + ' between ' + convert(varchar(60), begin_value) + ' and ' +
convert(varchar(60), end_value) + ' then ''' + value_code + '''' + char(13)+char(10)
from tableB
where @bdt between appl_begin_dt and appl_end_dt
set @sql = 'case ' + @sql + ' end'
set @sql = '
select
' + @sql + ' value_code
, count(distinct cust_key)
from tableA
where 1=1
and regdate >=' + quotename(@bdt, '''') + '
and regdate < ' + quotename(@edt, '''') + '
group by
' + @sql
print @sql
exec (@sql)
れ襦 れ螻 螳 覓語レ朱 ろ 蟆企. between join 蟆覲企 譟磯 觜襯伎 蟆?
select
case when umoney between 0 and 499999 then '8炎'
when val between 500000 and 4999999 then '7炎'
when val between 5000000 and 49999999 then '6炎'
when val between 50000000 and 499999999 then '5炎'
when val between 500000000 and 4999999999 then '4炎'
when val between 5000000000 and 49999999999 then '3炎'
when val between 50000000000 and 499999999999 then '2炎'
when val between 500000000000 and 9223372036854775807 then '1炎'
end value_code
, count(distinct cust_key)
from tableA
where 1=1
and a.regdate >='20101102'
and a.regdate < '20101103'
group by
case when umoney between 0 and 499999 then '8炎'
when val between 500000 and 4999999 then '7炎'
when val between 5000000 and 49999999 then '6炎'
when val between 50000000 and 499999999 then '5炎'
when val between 500000000 and 4999999999 then '4炎'
when val between 5000000000 and 49999999999 then '3炎'
when val between 50000000000 and 499999999999 then '2炎'
when val between 500000000000 and 9223372036854775807 then '1炎'
end