We help IT Professionals succeed at work.
Get Started

SQL Left Join not showing the results I expect

212 Views
Last Modified: 2015-04-03
I am trying to find missing entries for any give date in a query

For basic purposes I an only using two tables.
1: DateDim table that is populated with dates for the last 17 years  with a date field
2: Transaction Table that has a date field .

The Transaction table is missing the entire month for a certain user and the datedim table has dates that are populated up to today.

When I do a Left Outer Join datedim on transaction table I am expecting to get Null values for all of March, but it is returning only date values that the transactions table have

select top 10 Transdate,date from Dates D Left outer join Transactions T  on d.date =t.transdate
where Professionals = 'stombk0A8;1JLM' and Year(date) = '2015'
order by date desc

Open in new window


Results:
Transdate      date
2015-02-28 00:00:00.000      2015-02-28 00:00:00.000                
2015-02-28 00:00:00.000      2015-02-28 00:00:00.000
2015-02-27 00:00:00.000      2015-02-27 00:00:00.000
2015-02-27 00:00:00.000      2015-02-27 00:00:00.000
2015-02-27 00:00:00.000      2015-02-27 00:00:00.000
2015-02-26 00:00:00.000      2015-02-26 00:00:00.000
2015-02-26 00:00:00.000      2015-02-26 00:00:00.000
2015-02-26 00:00:00.000      2015-02-26 00:00:00.000
2015-02-25 00:00:00.000      2015-02-25 00:00:00.000
2015-02-25 00:00:00.000      2015-02-25 00:00:00.000

What I expected to see

Date      (No column name)
2015-04-02 00:00:00.000      NULL
2015-04-01 00:00:00.000      NULL
2015-03-31 00:00:00.000      NULL
2015-03-30 00:00:00.000      NULL
2015-03-29 00:00:00.000      NULL
2015-03-28 00:00:00.000      NULL
2015-03-27 00:00:00.000      NULL
2015-03-26 00:00:00.000      NULL
2015-03-25 00:00:00.000      NULL
2015-03-24 00:00:00.000      NULL
Comment
Watch Question
Senior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016
Commented:
This problem has been solved!
Unlock 1 Answer and 14 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE