I’m trying to find a workaround (hack) to some limitations preventing me from using a temporary table or a table variable in my SQL query.
I have a real table (technically it’s a derived table that results from an UNPIVOT of a poorly designed table) which lacks several necessary fields. I need to hardcode these fields into the result until we can cleanup the database issue.
Given a table like:
tblEntity
ID | Name
1 | One
2 | Two
I need to join several fields such as:
ID | Order
1 | 2
2 | 1
The join would result in:
ID | Name | Order
1 | One | 2
2 | Two | 1
My question is: can I join tblEntity to a resultset created like:
SELECT 1, 2
UNION ALL
SELECT 2, 1
Is it possible to join? If so, what is the syntax?
1 Answer