PARSENAME function is used to get the specified part of an object name. Parts of an object can be object name, owner name, database name, and server name.
It does not indicate whether or not an object by the specified name exists. It returns the specified part name of the given object name.
Syntax of PARSENAME Function :
PARSENAME ( 'object_name' , object_piece )
object_name is a name of an object. It is a sysname.
object_piece is an object part to return. It is of type integer. It can have below values.
Value | Description |
1 | Object name |
2 | Owner name |
3 | Database name |
4 | Server name |
Return type of PARSENAME function is nchar.
Examples of PARSENAME Function :
Example 1 : Use of PARSENAME function in select clause
SELECT PARSENAME('NorthWind..Customers',3) AS DatabaseName
Output
NorthWind
Above example returns database name of specified object.