with tb(AMsection,PMsection) as( select 4,3) select '上午第'+convert(varchar,number)+'节' from master..spt_values a,tb where type='p' and number>0 and number<=AMsection union all select '上午第'+convert(varchar,number)+'节' from master..spt_values a,tb where type='p' and number>0 and number<=pMsection
AMsection PMsection
4 3
就列出
上午第1节
上午第2节
上午第3节
上午第4节
下午第1节
下午第2节
下午第3节
with tb(AMsection,PMsection) as(
select 4,3)
select '上午第'+convert(varchar,number)+'节' from master..spt_values a,tb
where type='p' and number>0 and number<=AMsection
union all
select '上午第'+convert(varchar,number)+'节' from master..spt_values a,tb
where type='p' and number>0 and number<=pMsection