PARSENAME (Transact-SQL)
Returns the specified part of an object name. The parts of an object that can be retrieved are the object name, owner name, database name, and server name.
Note
|
|---|
|
The PARSENAME function does not indicate whether an object by the specified name exists. PARSENAME just returns the specified part of the specified object name. |
PARSENAME returns NULL if one of the following conditions is true:
-
Either object_name or object_piece is NULL.
-
A syntax error occurs.
The requested object part has a length of 0 and is not a valid Microsoft SQL Server identifier. A zero-length object name renders the complete qualified name as not valid.
The following example uses PARSENAME to return information about the Person table in the AdventureWorks2012 database.
USE AdventureWorks2012;
SELECT PARSENAME('AdventureWorks2012..Person', 1) AS 'Object Name';
SELECT PARSENAME('AdventureWorks2012..Person', 2) AS 'Schema Name';
SELECT PARSENAME('AdventureWorks2012..Person', 3) AS 'Database Name';
SELECT PARSENAME('AdventureWorks2012..Person', 4) AS 'Server Name';
GO
Here is the result set.
Object Name
------------------------------
Person
(1 row(s) affected)
Schema Name
------------------------------
(null)
(1 row(s) affected)
Database Name
------------------------------
AdventureWorks2012
(1 row(s) affected)
Server Name
------------------------------
(null)
(1 row(s) affected)

Note