I think you will need to use dynamic sql to achieve this.
Something like this:
<pre>create procedure sp1
DECLARE @sqlCommand varchar(1000);
SET @sqlCommand = ‘SELECT ‘ + @db_name + ‘.tableName.columnName FROM ‘ + @db_name + ‘.tableName, table2, table3 WHERE fieldX = 5′
Or I guess you can change the select statement to use an alias for the table, and use the variable just in the where clause:
<pre> SET @sqlCommand = ‘SELECT ALIAS.columnName FROM ‘ + @db_name + ‘.tableName ALIAS, table2, table3 WHERE fieldX = 5′</pre>
Just remember that dynamic sql pose some security issues, that need to be taken into consideration.
Hope this helps.