Reputation: 237
I have created 2 temp tables and I'm having problems joining them.
table #1
Create Table #First_Pay(
SAID int,
First_Payment date)
select b.CUSTNMBR, min(b.docdate) as first_payment
from RM20101 b
where b.CUSTNMBR = '1973204005'
and b.CHEKNMBR > '1'
Group by b.CUSTNMBR
table #2
Create Table #First_Bil(
SAID int,
First_Bill date)
Select a.CUSTNMBR, MIN(a.Tax_Date) as First_Bill
from SOP30200 as a
where a.CUSTNMBR = '1973204005'
Group by a.CUSTNMBR
and I used this query:
Select a.SAID, a.First_Bill, b.First_Payment
From #First_Bil a
Full Join
#First_Pay b
On a.SAID = b.SAID;
drop table #First_Bil
drop table #First_Pay
but I'm getting blanks. What am I doing wrong?
Upvotes: 2
Views: 9671
Reputation: 1764
I'm assuming you have data in your tables? you don't insert anywhere after you create them? Make sure to have an insert row
Upvotes: 0
Reputation: 204766
Instead of just selecting data after creating a temp table you have to insert it into the temp table:
Create Table #First_Pay(SAID int,
First_Payment date)
insert into #First_Pay select b.CUSTNMBR, min(b.docdate) as first_payment
from RM20101 b
where b.CUSTNMBR = '1973204005'
and b.CHEKNMBR > '1'
Group by b.CUSTNMBR
Create Table #First_Bil(SAID int,
First_Bill date)
insert into #First_Bil Select a.CUSTNMBR, MIN(a.Tax_Date) as First_Bill
from SOP30200 as a
where a.CUSTNMBR = '1973204005'
Group by a.CUSTNMBR
Upvotes: 1