过程中放入以下代码with n as ( select number from master..spt_values v where v.type='p' ) insert into t1 select (t2.year*12+t2.month+t3.number-1)/12 ,(t2.year*12+t2.month+t3.number-1)%12 +1 ,tt.[key] from tt join @data ttt on tt.[key]=ttt.[key] cross apply(select top 1 * from t1 where t1.[key]=tt.[key] order by 1 desc,2 desc) t2 cross apply(select * from n where n.number between 1 and (@year*12+@month-(t2.year*12+t2.month))) t3
我知道你这个实现功能。但是我说的方法不也是能够实现你的功能吗 这个脚本实在不知道怎么写 你建立一个表A年月表,里面只有一列(201401,201402.。。)里插入的时候用 select distinct [key]from t1 cross join a where a.years<把存储过程里面的参数转换下。and not exists ..
以为tt是你的表,原来是个类型。那直接用@data当左表就行 with n as ( select number from master..spt_values v where v.type='p' ) insert into t1 select (t2.year*12+t2.month+t3.number-1)/12 ,(t2.year*12+t2.month+t3.number-1)%12 +1 ,tt.[key] from @data tt cross apply(select top 1 * from t1 where t1.[key]=tt.[key] order by 1 desc,2 desc) t2 cross apply(select * from n where n.number between 1 and (@year*12+@month-(t2.year*12+t2.month))) t3
表A(只有一列2行,分别是A,B) 表B(只有一年 ,年份),表C (月份)进行CROSS JOIN 连接不就好了。
然后你需要到哪个日期截止 就用个选择条件。就好了。
好吧我没说清楚。
就是实现proc_test存储过程中的注释功能
根据传入的表类型数据往t1中插入数据。
好吧我没说清楚。
就是实现proc_test存储过程中的注释功能
根据传入的表类型数据往t1中插入数据。
我知道你这个实现功能。但是我说的方法不也是能够实现你的功能吗
好吧我没说清楚。
就是实现proc_test存储过程中的注释功能
根据传入的表类型数据往t1中插入数据。
我知道你这个实现功能。但是我说的方法不也是能够实现你的功能吗
这个脚本实在不知道怎么写
好吧我没说清楚。
就是实现proc_test存储过程中的注释功能
根据传入的表类型数据往t1中插入数据。
还有你存储过程里面的@DATE TT这个是干嘛的,需要把插入的数据存储进去吗?
好吧我没说清楚。
就是实现proc_test存储过程中的注释功能
根据传入的表类型数据往t1中插入数据。
还有你存储过程里面的@DATE TT这个是干嘛的,需要把插入的数据存储进去吗?
是的,我实际业务中是有很多信息的,我现在只是做了样本测试。
所以传入的数据我都用表类型来存储。
select number
from master..spt_values v
where v.type='p'
)
insert into t1
select
(t2.year*12+t2.month+t3.number-1)/12
,(t2.year*12+t2.month+t3.number-1)%12 +1
,tt.[key]
from tt
join @data ttt on tt.[key]=ttt.[key]
cross apply(select top 1 * from t1 where t1.[key]=tt.[key] order by 1 desc,2 desc) t2
cross apply(select * from n where n.number between 1 and (@year*12+@month-(t2.year*12+t2.month))) t3
好吧我没说清楚。
就是实现proc_test存储过程中的注释功能
根据传入的表类型数据往t1中插入数据。
我知道你这个实现功能。但是我说的方法不也是能够实现你的功能吗
这个脚本实在不知道怎么写
你建立一个表A年月表,里面只有一列(201401,201402.。。)里插入的时候用
select distinct [key]from t1 cross join a where a.years<把存储过程里面的参数转换下。and not exists ..
with n as (
select number
from master..spt_values v
where v.type='p'
)
insert into t1
select
(t2.year*12+t2.month+t3.number-1)/12
,(t2.year*12+t2.month+t3.number-1)%12 +1
,tt.[key]
from @data tt
cross apply(select top 1 * from t1 where t1.[key]=tt.[key] order by 1 desc,2 desc) t2
cross apply(select * from n where n.number between 1 and (@year*12+@month-(t2.year*12+t2.month))) t3