You will have to use Dynamic SQL and fire it off using EXEC() or sp_executesql.
DECLARE @vcSQL VARCHAR(8000) DECLARE @dbName VARCHAR(100) DECLARE @vcTableName VARCHAR(8000) SET @dbName = 'YOURDB' SET @vcTableName = 'YOURTABLE' SET @vcSQL = 'USE ' + @dbName + ' SELECT COUNT(*) FROM ' + @vcTableName + ' GO' EXEC (@vcSQL) HTH -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: 23 June 2005 16:36 To: CF-Talk Subject: Anyone know to do this in a SQL SP? Anyone know to do this in a SQL SP? I want to pass @dt_db which is the database. This code errors... CREATE procedure sp_populate_micros_temp_tables @dt_db varchar, @dt_date datetime as select A.* from @dt_db.dbo.[1micros_cc_auth_dtl] A, @dt_db.dbo.[1micros_trans_dtl] B GO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Logware (www.logware.us): a new and convenient web-based time tracking application. Start tracking and documenting hours spent on a project or with a client with Logware today. Try it for free with a 15 day trial account. http://www.houseoffusion.com/banners/view.cfm?bannerid=67 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:210362 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54