?
Solved

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

Posted on 2006-07-11
4
Medium Priority
?
324 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Expert Comment

by:RickBeebe
ID: 17081633
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 2000 total points
ID: 17081797
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
ID: 17081884
perfect!!!!!!!!!
thank you very much.
0
 
LVL 3

Expert Comment

by:RickBeebe
ID: 17081909
So, this is not a required busines rule?

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

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

752 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