I tried to set a left join, but when I did the group by
with one column and selected multiple columns I got an SQL error.
This is my query:
SELECT
b.ClientCode,
b.LastName, b.FirstName,
b."Id" AS IdClient,
c.CaseDate,
b.Gender,
b.BirthDate
FROM
dbo.Clients b
LEFT JOIN
dbo.ClientCases c ON c.ClientCode = b.ClientCode
WHERE
b.ClientCode LIKE '%1%'
AND DATEDIFF(DAY, '01/06/2017', c.CaseDate) >= 0
AND DATEDIFF(DAY, '05/06/2017', c.CaseDate) <= 0
GROUP BY
b.ClientCode
ORDER BY
b.ClientCode
When I write the query like this:
SELECT
b.ClientCode,
b.LastName, b.FirstName,
b."Id" AS IdClient,
c.CaseDate,
b.Gender,
b.BirthDate
FROM
dbo.Clients b
LEFT JOIN
dbo.ClientCases c ON c.ClientCode = b.ClientCode
WHERE
b.ClientCode LIKE '%1%'
AND DATEDIFF(DAY, '01/06/2017', c.CaseDate) >= 0
AND DATEDIFF(DAY, '05/06/2017', c.CaseDate) <= 0
GROUP BY
b.ClientCode, b.LastName, b.FirstName, b."Id",
b.Gender, b.BirthDate, c.CaseDate
ORDER BY
b.ClientCode
It's working - but it returns duplicate ClientCode
...
What can I do?