PARSENAME

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.

Syntax

PARSENAME ( 'object_name', object_piece )

Arguments

object_name

Is the name of the object for which to retrieve the specified object part. object_name is sysname. This parameter is an optionally-qualified object name. If all parts of the object name are qualified, this name can have four parts: the server name, the database name, the owner name, and the object name.

object_piece

Is the object part to return. object_piece is of type int, and can have these values:

Value Meaning
1 Object name
2 Schema name
3 Database name
4 Server name

Return types

nvarchar

Example

SELECT PARSENAME('AdventureWorks2012..Person', 3) AS 'Database Name';

See Also