Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Select from a table using only the id of the table in sysobjects

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-07-16 : 09:32:28
Joester writes "Is it possible to select from a table using the id of the table from sysobjects?"

M.E.
Aged Yak Warrior

539 Posts

Posted - 2002-07-16 : 10:08:10
Really don't know why you'd want to.. but dynamic SQL would work.

set a variable to the table name.. I'll call it @tablename (using sys objects to set it)
set @sql = 'select * from ' +@tablename

exec(@sql)

-----------------------
Take my advice, I dare ya
Go to Top of Page

dsdeming

479 Posts

Posted - 2002-07-16 : 12:58:15
You can pass the id to the OBJECT_NAME() function:


declare @vcCommand varchar( 1000 )
select @vcCommand = 'select * from ' + object_name( 194099732 )
print @vcCommand
execute ( @vcCommand )

However, if you know the id, shouldn't you already know the name?

Go to Top of Page
   

- Advertisement -