I have a query like this:
;WITH A AS (SELECT * FROM T1 where T1.targetDate=@inputdate),
B AS (SELECT A.*, T2.SId, T2.Type, T2.Value
FROM A
INNER JOIN T2 ON A.SId = T2.SId )
SELECT A.*, B.Type, B.Value
FROM B
My question is, instead of getting the Value
for @inputdate,
how to get the delta of Value
between @inputdate
and the previous day (DATEADD(day, -1, @inputdate ))
?
Edited:
Sorry for not being clear, the 'Value' is of type int. For example, if @inputdate = '20130708'
, the Value
for '20130708' is 30, and the 'Value' for previous day '20130707' is 20, so it should return (30 - 20) which is 10.