October 6, 2005 at 1:04 am
Hi,
For any SQL query ,Can i get the name of the database and the server name from the table and put that in The FROM clause
something like..
Select * as DBName from Table1
set @DBname =DBName
Select * from @DBName
Or can u suggest the way of getting the DBName and the Server name dynamically and then running the SQLQuery
Regards
Jyoti
October 6, 2005 at 1:34 am
select db_name() - this gets you the name of the current database context
select @@servername - this gets you the name of the server
October 7, 2005 at 7:56 am
Here's a working example that executes a 'select *' on dbo.Table:
DECLARE @SQLString nvarchar(100)
set @SQLString = N'select * from '+ @@servername + '.' + db_name() + '.dbo.Table'
PRINT @SQLSTRING
EXEC(@SQLString)
Norene Malaney
October 7, 2005 at 11:55 am
Hi,
Can these commands be used in VB as well? Or would you recommend a different method?
Thanks
- Beach
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply