Solved

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

Posted on 2006-07-11
4
289 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
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 500 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
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.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
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

948 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

23 Experts available now in Live!

Get 1:1 Help Now