August 25, 2005 at 11:36 am
Does anyone know if it's possible to use a variable with a USE statement? ie:
declare @dbname varchar(100)
set @dbname = 'Some Database'
use @dbname
dbcc shrinkfile ('File', Size)
August 25, 2005 at 12:10 pm
No, I don't think so. I've always had to use conditionals, e.g.
if @dbase = 'foo' use foo
if @dbase = 'bar' use bar
August 25, 2005 at 12:16 pm
I was hoping it wouldn't come to that. Thanks for the input.
August 25, 2005 at 12:21 pm
Why do you want to do exactly?
August 25, 2005 at 8:13 pm
declare @dbname varchar(100)
set @dbname = 'Some Database'
DECLARE @sql VARCHAR(8000)
SET @sql = 'use ' + @dbname
+ ' dbcc shrinkfile (''File'', Size)'
EXEC (@SQL)
...should work for what you identified but, like Remi said, what is it you really want to do?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply