I want to be able to inner join two tables based on the result of an expression.
What I\'ve been trying so far:
INNER JOIN CASE WHEN Reg
You probably need to perform two left joins, one onto TimeRegistration
and one onto DrivingRegistration
, and return the fields you want from the appropriate join table something like this:
LEFT JOIN TimeRegistration ON TimeRegistration.RegistreringsId = R.Id
LEFT JOIN DrivingRegistration ON DrivingRegistration.RegistreringsId = R.Id
and you select statement would be something like this:
SELECT CASE WHEN RegT.Type = 1 THEN TimeRegistration.Foo ELSE DrivingRegistration.Bar END
I like what you're trying to do, but I don't think SQL is that clever.