1:其实我感觉没有那么复杂。我们只关心他们的差就可以了。
--variables
DECLARE @t table(ItemId int identity,CreatedTime datetime,height float,weight float,note ntext)
DECLARE @i int
--prepare data
SET @i=1
WHILE @i<12
BEGIN
INSERT INTO @t select DATEADD(day,@i,GETDATE()),@i,@i,'test'+CAST(@i as nvarchar(4000))
SET @i=@i+1
END
--add mutiple data
INSERT INTO @t select DATEADD(day,3,GETDATE()),4,4,'test'+CAST(4 as nvarchar(4000))
--delete one data
delete @t where Itemid=4
--display all
SELECT * FROM @t
DECLARE @param datetime
SEt @param=DATEADD(day,3,GETDATE())
SELECT *,DateDiff(day,CreatedTime,@param) as interval FROM @t
--1 2008-08-28 09:29:51.810 1 1 test1 2
--2 2008-08-29 09:29:51.810 2 2 test2 1
--3 2008-08-30 09:29:51.810 3 3 test3 0
--5 2008-09-01 09:29:51.810 5 5 test5 -2
--6 2008-09-02 09:29:51.810 6 6 test6 -3
--7 2008-09-03 09:29:51.810 7 7 test7 -4
--8 2008-09-04 09:29:51.810 8 8 test8 -5
--9 2008-09-05 09:29:51.810 9 9 test9 -6
--10 2008-09-06 09:29:51.810 10 10 test10 -7
--11 2008-09-07 09:29:51.810 11 11 test11 -8
--12 2008-08-30 09:29:51.810 4 4 test4 0