我有一个记录,我希望根据月份拆分。当我进行拆分时,我试图按原样复制所有数据,但只对增量更改 FromMonth 字段感兴趣。
例如,
Record to be split:
c1 c2 c3 c4 FromMonth ToMonth Y
---------------------------------------
AA BB CC DD Feb Dec 2013
Resultant Records:
1.)
c1 c2 c3 c4 FromMonth ToMonth Y
---------------------------------------
AA BB CC DD Mar Dec 2013
2.)
c1 c2 c3 c4 FromMonth ToMonth Y
---------------------------------------
AA BB CC DD Apr Dec 2013
3.)
c1 c2 c3 c4 FromMonth ToMonth Y
---------------------------------------
AA BB CC DD May Dec 2013
.
.
.
.
任何建议或解决方法都会很有用。
这是我所做的,我是新手,我只是在学习:
DECLARE @FromMonth Int;
DECLARE @ToMonth Int;
DECLARE @Result int;
DECLARE @C1 int;
DECLARE @C2 int;
DECLARE @C3 int;
DECLARE @C4 decimal(20,8);
DECLARE @C5 uniqueidentifier;
DECLARE @C6 varchar(1000);
DECLARE @C7 int;
DECLARE @C8 int;
DECLARE @C9 int;
DECLARE @C10 bit;
DECLARE @C11 date;
DECLARE @C12 date;
set @FromMonth = (select FromMonth from master..t where t.c1=1 );
set @ToMonth = (select ToMonth from master.t where t.c1=1 );
set @Result=@ToMonth - @FromMonth;
while(@Result!=0)
begin
set @FromMonth = @FromMonth+1
insert into master..t(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,FromMonth,ToMonth)
values(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,@FromMonth,ToMonth);
set @Result = @Result -1;
break;
end;
谢谢,