I have a table jobs with a column StartDate that is often null. If it is not null this is what I want to inner join with a table quarters on, otherwise I want to inner join on some other conditions. This is sort of what I want:
INNER JOIN Quarters q
ON (IF j.StartDate IS NOT NULL (j. StartDate BETWEEN GETDATE() and q.EndDate)
ELSE **Some other condition**)
The error that comes up when this is run is that there is incorrect syntax near the keyword 'IF'
Does anyone know the correct syntax for this?
Thanks in advance for your help!
INNER JOIN Quarters q ON
(j.StartDate IS NOT NULL AND j. StartDate BETWEEN GETDATE() and q.EndDate)
OR
(j.StartDate IS NULL AND **Some other condition**)
The easiest way to handle this is just to treat it as a logical operation:
ON (j.StartDate IS NOT NULL
and j. StartDate BETWEEN GETDATE() and q.EndDate)
OR (some other condition)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With