Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

amount difference between 2 dats Expand / Collapse
Author
Message
Posted Thursday, September 11, 2008 9:45 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Yesterday @ 11:47 AM
Points: 41,525, Visits: 34,442
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

Post #567873
Posted Sunday, September 14, 2008 12:34 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, May 09, 2012 4:31 AM
Points: 89, Visits: 231
Thanks Gila
Post #569146
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse