Solved

join Tables for Calendar Query, show all records from reference Table.

Posted on 2006-07-11
4
278 Views
Last Modified: 2008-03-10
Hi experts,
I have following query. And in my solution i want to see each day from for example the month july, even if i have no values entered in tblMAAbsenzen. But, unfortunately I do not get the dates if I have another ma_id, with values in tblMAAbsenzen. I want to make this query for a better view.
Thanks in advance for your help.
lanter007

SELECT     refCalendar.Datum, tblMAAbsenzen.ma_id, tblMAAbsenzen.absenz_id AS ferien, tblMAAbsenzen.absenz_id AS krankheit,
                      tblMAAbsenzen.absenz_id AS unfall, tblMAAbsenzen.absenz_id AS militaer, tblMAAbsenzen.absenz_id AS mutterschaft,
                      tblMAAbsenzen.absenz_id AS kompensation, tblMAAbsenzen.absenz_id AS umzug, tblMAAbsenzen.absenz_id AS todesfall,
                      tblMAAbsenzen.absenz_id AS heirat, tblMAAbsenzen.absenz_id AS feiertag, tblMAAbsenzen.absenz_id AS pflege, tblMAAbsenzen.dauer_in_tagen,
                      MONTH(refCalendar.Datum) AS Monat, YEAR(refCalendar.Datum) AS Jahr
FROM         refCalendar LEFT OUTER JOIN
                      tblMAAbsenzen ON refCalendar.Datum = tblMAAbsenzen.datum
WHERE     (MONTH(refCalendar.Datum) >= 7) AND (MONTH(refCalendar.Datum) <= 8) AND (YEAR(refCalendar.Datum) = 2006) AND (tblMAAbsenzen.ma_id = 11 OR
                      tblMAAbsenzen.ma_id IS NULL)
ORDER BY refCalendar.Datum
0
Comment
Question by:lanter007
  • 2
4 Comments
 
LVL 3

Expert Comment

by:RickBeebe
Comment Utility
If all the dates for July exist in refCalendar - all the rows will display with nulls for all columns except for refCalendar.Datum where they don't exist on tblMAAbsenzen.  If they do exist on tblMAAbsenzen the ma_id is 11 or null the entire row will show.
0
 
LVL 28

Accepted Solution

by:
imran_fast earned 500 total points
Comment Utility
try this
====

SELECT     refCalendar.Datum, tblMAAbsenzen.ma_id, tblMAAbsenzen.absenz_id AS ferien, tblMAAbsenzen.absenz_id AS krankheit,
                      tblMAAbsenzen.absenz_id AS unfall, tblMAAbsenzen.absenz_id AS militaer, tblMAAbsenzen.absenz_id AS mutterschaft,
                      tblMAAbsenzen.absenz_id AS kompensation, tblMAAbsenzen.absenz_id AS umzug, tblMAAbsenzen.absenz_id AS todesfall,
                      tblMAAbsenzen.absenz_id AS heirat, tblMAAbsenzen.absenz_id AS feiertag, tblMAAbsenzen.absenz_id AS pflege, tblMAAbsenzen.dauer_in_tagen,
                      MONTH(refCalendar.Datum) AS Monat, YEAR(refCalendar.Datum) AS Jahr
FROM         refCalendar
      LEFT OUTER JOIN
                      tblMAAbsenzen ON refCalendar.Datum = tblMAAbsenzen.datum
                  AND (tblMAAbsenzen.ma_id = 11 OR
                            tblMAAbsenzen.ma_id IS NULL)
WHERE     (MONTH(refCalendar.Datum) >= 7) AND (MONTH(refCalendar.Datum) <= 8) AND (YEAR(refCalendar.Datum) = 2006)
            
ORDER BY refCalendar.Datum
0
 

Author Comment

by:lanter007
Comment Utility
perfect!!!!!!!!!
thank you very much.
0
 
LVL 3

Expert Comment

by:RickBeebe
Comment Utility
So, this is not a required busines rule?

AND (tblMAAbsenzen.ma_id = 11 OR
                      tblMAAbsenzen.ma_id IS NULL)
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now