My problem is a more advanced use of the CASE function. Basically, depending upon one of the values in my resultset, I want to get a value from one of two different databases.
An illustration of the problem would be:
Suppose I have the query:
SELECT drd_id, drd_description FROM Widgets
Now, if drd_description is 1 I want to get a value from the database OLD_Widgets, if 2 then I want a value from the database NEW_Widgets. I tried using CASE along the lines of:
SELECT drd_id, Description = CASE drd_Description
WHEN 1 THEN SELECT DESCRIPTION FROM [Old_Widgets].dbo.description dcs WHERE dcs.id = drd_description
WHEN 2 THEN SELECT DESCRIPTION FROM [New_Widgets].dbo.description dcs WHERE dcs.id = drd_description
END
Unfortnately, it would appear that CASE doesn't support the SELECT statement within it. Does anyone know how I can achieve a similar result?
An illustration of the problem would be:
Suppose I have the query:
SELECT drd_id, drd_description FROM Widgets
Now, if drd_description is 1 I want to get a value from the database OLD_Widgets, if 2 then I want a value from the database NEW_Widgets. I tried using CASE along the lines of:
SELECT drd_id, Description = CASE drd_Description
WHEN 1 THEN SELECT DESCRIPTION FROM [Old_Widgets].dbo.description dcs WHERE dcs.id = drd_description
WHEN 2 THEN SELECT DESCRIPTION FROM [New_Widgets].dbo.description dcs WHERE dcs.id = drd_description
END
Unfortnately, it would appear that CASE doesn't support the SELECT statement within it. Does anyone know how I can achieve a similar result?