I am trying to use Variable with Alias in LEFT JOIN. I do not want to use Procedures (EXEC) or putting all the query as a string in a variable and I could not find any example on the internet.
I tried this way but it generated Syntax Error.
DECLARE @CustomerID AS INT =1
select top 5 * from ABC.dbo.Table1 t1
left join XYZ.dbo.Table2 t2
on t1.@CustomerID = t2.@CustomerID
The real query is pretty long but if this works that will also work for the rest as it has many LEFT JOINs.
New contributor
Iftikhar Ali is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.