Avatar of erezabou
erezabou
 asked on

missing records

hi experts,

here is my view

 SELECT
  dbo.orcCHAMBRES.NUMCHB,
  dbo.orcCHAMBRES.TYPCHB,
  dbo.orcCHAMBRES.ETATCHAMB,
  dbo.orcPLANNING.DATEARRIV,
  dbo.orcPLANNING.NBADULTES,
  dbo.orcPLANNING.NOMCLI,
  dbo.orcPLANNING.NUMSEJOUR,
  dbo.orcSEJOURS.COMMENT,
  dbo.orcSEJOURS.MEMO,
  max( dbo.orcSEJOURS.DATEDEPART) AS max_planning_date
FROM
  dbo.orcCHAMBRES
  LEFT OUTER JOIN dbo.orcPLANNING ON (dbo.orcCHAMBRES.NUMCHB = dbo.orcPLANNING.NUMCHB)
  LEFT OUTER JOIN dbo.orcSEJOURS ON (dbo.orcPLANNING.NUMSEJOUR = dbo.orcSEJOURS.NUMSEJOUR)
WHERE
  dbo.orcPLANNING.DATEARRIV LIKE '20110715' AND
  dbo.orcCHAMBRES.TYPCHB NOT LIKE 'SALO'
GROUP BY
  dbo.orcCHAMBRES.NUMCHB,
  dbo.orcCHAMBRES.TYPCHB,
  dbo.orcCHAMBRES.ETATCHAMB,
  dbo.orcPLANNING.DATEARRIV,
  dbo.orcPLANNING.NBADULTES,
  dbo.orcPLANNING.NOMCLI,
  dbo.orcPLANNING.NUMSEJOUR,
  dbo.orcSEJOURS.COMMENT,
  dbo.orcSEJOURS.MEMO,
  dbo.orcSEJOURS.DATEDEPART
ORDER BY
  dbo.orcCHAMBRES.NUMCHB

I need it to be modified in order to show all the records from  dbo.orcCHAMBRES even if other tqbles have no values

thank
Microsoft SQL Server 2008Microsoft SQL Server

Avatar of undefined
Last Comment
G Trurab Khan

8/22/2022 - Mon
deighton

try changing where condition, missing records in orcPLANNING cannot be matched if their value is forced to have a particular value like you have


WHERE (dbo.orcPLANNING.DATEARRIV LIKE '20110715' OR dbo.orcPLANNING.DATEARRIV IS NULL) AND
  dbo.orcCHAMBRES.TYPCHB NOT LIKE 'SALO'
deighton

or even
 SELECT
  dbo.orcCHAMBRES.NUMCHB,
  dbo.orcCHAMBRES.TYPCHB,
  dbo.orcCHAMBRES.ETATCHAMB,
  zz.DATEARRIV,
  zz.NBADULTES,
 zz.NOMCLI,
  zz.NUMSEJOUR,
  dbo.orcSEJOURS.COMMENT,
  dbo.orcSEJOURS.MEMO,
  max( dbo.orcSEJOURS.DATEDEPART) AS max_planning_date
FROM
  dbo.orcCHAMBRES
  LEFT OUTER JOIN (SELECT * FROM dbo.orcPLANNING  dbo.orcPLANNING.DATEARRIV LIKE '20110715' ) zz ON (dbo.orcCHAMBRES.NUMCHB = zz.NUMCHB) 
  LEFT OUTER JOIN dbo.orcSEJOURS ON (dbo.orcPLANNING.NUMSEJOUR = dbo.orcSEJOURS.NUMSEJOUR)
WHERE
    dbo.orcCHAMBRES.TYPCHB NOT LIKE 'SALO'
GROUP BY
  dbo.orcCHAMBRES.NUMCHB,
  dbo.orcCHAMBRES.TYPCHB,
  dbo.orcCHAMBRES.ETATCHAMB,
  zz.DATEARRIV,
  zz.NBADULTES,
  zz.NOMCLI,
  zz.NUMSEJOUR,
  dbo.orcSEJOURS.COMMENT,
  dbo.orcSEJOURS.MEMO,
  dbo.orcSEJOURS.DATEDEPART
ORDER BY
  dbo.orcCHAMBRES.NUMCHB

Open in new window

Lowfatspread

you need to cater for any of the left join conditionals equating to null...

normally thats easiest achieved by puting the conditions directly into the "table"  specification
SELECT 
  dbo.orcCHAMBRES.NUMCHB,
  dbo.orcCHAMBRES.TYPCHB,
  dbo.orcCHAMBRES.ETATCHAMB,
  p.DATEARRIV,
  p.NBADULTES,
  p.NOMCLI,
  p.NUMSEJOUR,
  dbo.orcSEJOURS.COMMENT,
  dbo.orcSEJOURS.MEMO,
  max( dbo.orcSEJOURS.DATEDEPART) AS max_planning_date
FROM
  dbo.orcCHAMBRES
  LEFT OUTER JOIN (select * from dbo.orcPLANNING 
                     where DATEARRIV LIKE '20110715') as P
ON (dbo.orcCHAMBRES.NUMCHB = p.NUMCHB)
  LEFT OUTER JOIN dbo.orcSEJOURS 
    ON (p.NUMSEJOUR = dbo.orcSEJOURS.NUMSEJOUR)
WHERE
  
  dbo.orcCHAMBRES.TYPCHB NOT LIKE 'SALO'
GROUP BY
  dbo.orcCHAMBRES.NUMCHB,
  dbo.orcCHAMBRES.TYPCHB,
  dbo.orcCHAMBRES.ETATCHAMB,
  p.DATEARRIV,
  p.NBADULTES,
  p.NOMCLI,
  p.NUMSEJOUR,
  dbo.orcSEJOURS.COMMENT,
  dbo.orcSEJOURS.MEMO,
  dbo.orcSEJOURS.DATEDEPART
ORDER BY
  dbo.orcCHAMBRES.NUMCHB

Open in new window

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
G Trurab Khan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question