Last post Mar 01, 2012 04:24 AM by D J
Mar 01, 2012 01:47 AM|-_-|LINK
i would like to join two tables and they are in different database in sp by passing @table_name. there is error , why??
select a.id,b.id from databaseA.'+@table_name+' a inner join
databaseB.'+@table_name b on a.name=b.name'
there is error about database name, how to join.
Mar 01, 2012 04:16 AM|vendan|LINK
Try like this,
Declare @sql Varchar(500)
SET @sql='select a.id,b.id from databaseA.'+@table_name+' a inner join
databaseB.'+@table_name+' b on a.name=b.name'
Mar 01, 2012 04:24 AM|D J|LINK
Use like databaseA.DBO.'+@table_name