日期:2014-05-16 浏览次数:20686 次
IF OBJECT_ID('TEMPDB.DBO.#tb') IS NOT NULL DROP TABLE #tb
GO
CREATE TABLE #tb
(
userid VARCHAR(4),
trading DATETIME,
rt float
)
insert into #tb
values('0001','2012-12-01',0.3),
('0001','2012-12-02',0.6),
('0001','2012-12-03',0.4),
('0001','2012-12-04',0.8),
('0002','2012-11-01',0.5),
('0002','2012-11-02',0.5),
('0002','2012-11-03',0.6)
CREATE TABLE tb
(userid VARCHAR(4),
trading DATETIME,
rt float)
insert into tb
values
('0001','2012-12-01',0.3),
('0001','2012-12-02',0.6),
('0001','2012-12-03',0.4),
('0001','2012-12-04',0.8),
('0002','2012-11-01',0.5),
('0002','2012-11-02',0.5),
('0002','2012-11-03',0.6)
-- 累计乘函数
create function dbo.fn_multiply
(@u varchar(4),
@t datetime) returns float
as
begin
declare @x float
select @x=1.0
select @x=@x*rt
from tb
where userid=@u and trading<=@t
return @x
end
-- 累计除函数
create functi