August 16, 2012 at 9:34 am
I use the "OBJECT_NAME' function in conjunction with systems tables to return the names of objects given their object_id. Up until yesterday, this worked fine. When I use the same function now, I get a null value in the column that is supposed to return the object name. I tried reconnecting to the server and trying the function on different DBs, but I am getting the same results. Does anyone know why this would occur?
August 16, 2012 at 9:37 am
It still works. But it will give a null result if the number isn't valid in the context of the connection it's being run in.
If, for example, the connection is to master, and the object_id you are querying is for something in a user database, then odds are you'll get NULL, unless master uses the same number for a different object.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
August 16, 2012 at 9:46 am
I wasn't specifying the database to use. I explicitly designated the DB to use in the session and the names reappeared
August 16, 2012 at 10:52 am
if you run this command, are the results null for the ObjectName? I've never heard of the built in function not working correctly, it's usually because of the issues Gsqared mentions, wrong object_id(doesn't exist) or wraong database context.
SELECT
OBJECT_NAME(object_id) As ObjectName,
object_id,
name
FROM sys.objects
Lowell
August 16, 2012 at 11:10 am
guerillaunit (8/16/2012)
I wasn't specifying the database to use. I explicitly designated the DB to use in the session and the names reappeared
Okay. That means it was connecting to the default databases for your login (almost always master). That makes sense.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply