So I had a little time to play with this script. I found where you introduced a bug when you added the square braces around your table name, where by you would never the table name on the following statement:
WHERE i.name = @Result
However by doing a compare on object_id should be sufficient so I changed your where clause to read"
WHERE i.object_id = @objectID
Also, I'm no big fan on looking for nulls the way you described in this construct:
and (name not like 'null')
When I look for nulls (or not null) I would use the following construct:
and name not null
So there is my 2 cents worth. These types of scripts teach you a lot about SQL Server. If you are fluent with the system tables and can spin up code rather quickly, then by all means roll your own. However there are a great number of resources where fellow DBAs have plowed that road before you and you can get something up and fully functional with little to no effort. So in other words, no need to reinvent the wheel as a number of others have pointed out before.
Kurt
Kurt W. Zimmerman
SR DBA
Lefrak Organization
New York, NY
http://www.linkedin.com/in/kurtwzimmerman