Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

TSQL Help

$
0
0

I am trying to find the solution for the following, Any help would be hightly appreciated.

CREATE TABLE #A
(
CustomerId int,
TranDate datetime,
TranCount int
)

CREATE TABLE #B
(
CustomerId int,
TranDate datetime,
TranCount int
)

insert into #a
values
(1,'2014-01-01 01:00:00.000',10),
(1,'2014-01-01 02:00:00.000',5),
(1,'2014-01-03 01:00:00.000',5),
(1,'2014-01-04 02:00:00.000',80)


insert into #b
values
(1,'2014-01-01 02:00:00.000',10),
(1,'2014-01-01 03:00:00.000',5),
(1,'2014-01-02 01:00:00.000',20),
(1,'2014-01-02 03:00:00.000',15),
(2,'2014-01-01 01:00:00.000',5),
(2,'2014-01-01 02:00:00.000',80)

Result Needed:

CustomerId TranDate     TranCount-A  TranCountB
1                2014-01-01   5                  5
1                2014-01-02   0                  15
1                2014-01-03   5                  15
1                2014-01-04   80                15
2                2014-01-01   0                  80

TranCount-A : This is the values that appeared the latest in that day.

TranCount-B : This is the value that appeared the latest in that day. But after this day the value
needs to continue till the point the value got changed in some other day.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>