Question : Quick question on Joins

Hi experts,

I was wondering why the following won't work in sql:

declare @joining varchar(100)
set @joining = 't3.Col1'
select * from tblTestData t1 inner join tblTestData3 t3 on t1.Col1 = @joining

I get a empty result from the above even though both tables have exactly the same data.
Is it not possible to join based on a variable?

Answer : Quick question on Joins

>so why doesn't it throw an error?
it will join on the litteral value  't3.Col1' , meaning the string  't3.Col1', and not on the value of the column col1 of table t3.
the @variable will not be interpreted as table.column expression, but as it is declared, as a string.
Random Solutions  
 
programming4us programming4us