我有一个表
table1(InvoiceDate char(10),x int)
数据为
InvoiceDate, x
2006-03-01 5
2006-03-02 8
2006-03-03 10
我需要把把新的数据插入到表table1里边去,
新的从table1中取得
新数据为:
2006-03-01 5
2006-03-02 13
2006-03-03 23
如果是一个月的第一天,那么X为原来的值
如果不是第一天就要把前面的X的值相加得到
问题解决,马上结帖
table1(InvoiceDate char(10),x int)
数据为
InvoiceDate, x
2006-03-01 5
2006-03-02 8
2006-03-03 10
我需要把把新的数据插入到表table1里边去,
新的从table1中取得
新数据为:
2006-03-01 5
2006-03-02 13
2006-03-03 23
如果是一个月的第一天,那么X为原来的值
如果不是第一天就要把前面的X的值相加得到
问题解决,马上结帖
InvoiceDate,
(Select SUM(x) From table1 Where InvoiceDate<=A.InvoiceDate) As x
From table1 A
Insert @t Select '2006-03-01',5
Union all Select '2006-03-02',8
Union all Select '2006-03-03',10--
Select * ,
V=(Select Sum(X) From @t Where InvoiceDate<=A.InvoiceDate)
From @t A
Insert @t Select '2006-03-01',5
Union all Select '2006-03-02',8
Union all Select '2006-03-03',10--
Update A
Set X=(Select Sum(X) From @t Where InvoiceDate<=A.InvoiceDate)
From @t A
--结果
Select * From @t
--鱼兄快啊:)
x int
)insert @t select '2006-03-01',5
union select '2006-03-02',8
union select '2006-03-03',10select invoicedate,x=(select sum(x) from @t where invoicedate<=a.invoicedate) from @t a