Hey Troops,
I'm not sure if this is allowed, but I'm trying to keep my SP generic and reduce duplicate code. Depending on a condition, I need to JOIN to different tables, which slightly changes the result set. So, I would include conditions later to grab the proper fields based on checking the same condition (@TravelType = 'A').
Here's a sample of what I'm doing, which is currently giving me a syntax error near 'CASE':
CASE WHEN @TravelType = 'A'
THEN
LEFT JOIN AirportCity DepCity
ON DepFrom = DepCity.Code
LEFT JOIN AirportCity ArrCity
ON ArrTo = ArrCity.Code
ELSE
LEFT JOIN City DepCity
ON DepartureAirpor tCode = DepCity.CityCod e
AND DepCity.TypeCod e = 'R'
LEFT JOIN City ArrCity
ON ArrivalAirportC ode = ArrCity.CityCod e
AND ArrCity.TypeCod e = 'R'
END
Can someone shed some light on why this throws an error? Or, is there another way to accomplish such?
Thanks!
I'm not sure if this is allowed, but I'm trying to keep my SP generic and reduce duplicate code. Depending on a condition, I need to JOIN to different tables, which slightly changes the result set. So, I would include conditions later to grab the proper fields based on checking the same condition (@TravelType = 'A').
Here's a sample of what I'm doing, which is currently giving me a syntax error near 'CASE':
CASE WHEN @TravelType = 'A'
THEN
LEFT JOIN AirportCity DepCity
ON DepFrom = DepCity.Code
LEFT JOIN AirportCity ArrCity
ON ArrTo = ArrCity.Code
ELSE
LEFT JOIN City DepCity
ON DepartureAirpor tCode = DepCity.CityCod e
AND DepCity.TypeCod e = 'R'
LEFT JOIN City ArrCity
ON ArrivalAirportC ode = ArrCity.CityCod e
AND ArrCity.TypeCod e = 'R'
END
Can someone shed some light on why this throws an error? Or, is there another way to accomplish such?
Thanks!
Comment