September 21, 2011 at 5:33 am
Hi All,
I am trying to to execute below script:
DECLARE @intFlag varchar(30)
set @intFlag = 'test'
exec( 'use '+@intFlag)
select * from sysobjects where xtype='u'
But its not working.
Here I want to pass the database naem using a variable to change the database context like
Use Dbname as USE @variable.
How can we achieve it.
Thank You.
Regards,
Raghavender Chavva
September 21, 2011 at 5:37 am
You'd need to have both the use and the next select in the same dyamic sql call.
What do you need to do exactly?
September 21, 2011 at 5:46 am
September 21, 2011 at 6:04 am
September 21, 2011 at 6:21 am
you could also use three part naming, and not use the USE command at all:
select * from test.dbo.sysobjects where xtype='u'
--or
select * from test.sys.tables
Lowell
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy