一个SQL语句的不知道怎么写,请帮忙
工号,结算日期,奖金
---------------------
A,2012-7-1,200
B,2012-9-1,100
因为这个奖金是发六个月的,所以我想得到这样:
A,2012-7-1,200
A,2012-8-1,200
A,2012-9-1,200
A,2012-10-1,200
A,2012-11-1,200
A,2012-12-1,200
B,2012-9-1,200
B,2012-10-1,200
B,2012-11-1,200
B,2012-12-1,200
B,2013-1-1,200
B,2013-1-1,200
------解决方案--------------------with tb(工号,结算日期,奖金)
as(
select 'A','2012-7-1',200 union all
select 'B','2012-9-1',100
)
select 工号,dateadd(month,number,结算日期) 结算日期,奖金 from tb, master..spt_values where type='p' and number between 0 and 5 order by 工号,dateadd(month,number,结算日期)
------解决方案--------------------
create table emp(empid nvarchar(1),jsrq varchar(10),bonus int)
insert into emp
select N'A','2012-07-01',200
union all
select N'B','2012-09-01',100
select a.empid,dateadd(month,b.number,jsrq) jsrq,bonus from emp a,master..spt_values b where b.type='p' and b.number<=5