Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-07-11
4
Medium Priority
?
332 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

609 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