It is very likely that you need to do the join with clients, probably you have to add a left or right join with clients or change the innerjoin for a leftjoin and force all the clients out, to say that the date can be the date or null you can use coalesce()
link
link
In such a way that coalesce(fechaorden, null)
will return or the date of the order or null
.
Here is a similar example
SELECT md.new_name,md.new_motivodecisionid,
coalesce(rm.new_relacionmotivosid,'-1') as new_relacionmotivosid,
rm.new_motivoeleccion, rm.new_motivorenuncia
FROM new_motivodecision md
left join new_relacionmotivos rm on rm.new_motivodecisionid = md.new_motivodecisionid
and rm.new_opportunityid = 'xxx-xxx-xxx' Where md.statecode = 0
Here I am taking all the decision reasons whether or not they have a relationship with the Oportunity entity, with coalesce()
if the entity new_relacionmotivos
does not contain a new_motivoeleccionid
next to Oportunityid
marks the new_relacionmotivosid
as '-1'
, in your case it would be null
Since I do not know what structure of data you have a possible example of the case that you mention to me, it would be the following
SELECT clienteid ,productoid , coalesce(fechaorden, null)
FROM Ventas.Ordenes INNER JOIN Ventas.DetallesOrden
ON Ordenes.ordenid = DetallesOrden.ordenid
left join Ventas.Clientes on Ordenes.clienteid = Clientes.clienteid
Where fechaorden ='2016-02-12';
or
SELECT clienteid ,productoid , coalesce(fechaorden, null)
FROM Ventas.Ordenes INNER JOIN Ventas.DetallesOrden
ON Ordenes.ordenid = DetallesOrden.ordenid
Where fechaorden ='2016-02-12';