|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 3:31 PM
Points: 37,720,
Visits: 29,974
|
|
Does this work?
-- first, some setup.
CREATE TABLE #Amounts ( SomeDate DATETIME, SomeAmount INT )
insert into #Amounts values ('2008/09/01',500) insert into #Amounts values ('2008/09/02',1500) insert into #Amounts values ('2008/09/03',3500)
-- Setup finished
CREATE TABLE #WorkTable ( RowID INT IDENTITY PRIMARY KEY, SomeDate DATETIME, SomeAmount INT )
INSERT INTO #WorkTable (SomeDate, SomeAmount) SELECT SomeDate, SomeAmount FROM #Amounts ORDER BY SomeDate SELECT CurrentDay.SomeDate, CurrentDay.SomeAmount-PreviousDay.SomeAmount from #WorkTable PreviousDay inner join #WorkTable CurrentDay on PreviousDay.RowID = CurrentDay.RowID - 1
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Wednesday, May 09, 2012 4:31 AM
Points: 89,
Visits: 231
|
|
|
|
|