Export (0) Print
Expand All
ABS
ALL
AND
ANY
AVG
bit
COS
COT
DAY
EXP
GO
IN
LEN
LOG
MAX
MIN
NOT
OR
PI
SET
SIN
STR
SUM
TAN
USE
VAR
Expand Minimize

PARSENAME

SQL Server 2000

Returns the specified part of an object name. 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 or not an object by the specified name exists. It just returns the specified piece of the given object 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 consist of 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 int, and can have these values.

Value Description
1 Object name
2 Owner name
3 Database name
4 Server name

Return Types

nchar

Remarks

PARSENAME returns NULL if any of the following conditions are met:

  • Either object_name or object_piece is NULL.

  • A syntax error occurs.

  • The requested object part has a length of 0 and is an invalid Microsoft® SQL Server™ identifier. A zero-length object name renders the entire qualified name invalid.
Examples

This example uses PARSENAME to return information about the authors table in the pubs database.

USE pubs
SELECT PARSENAME('pubs..authors', 1) AS 'Object Name'
SELECT PARSENAME('pubs..authors', 2) AS 'Owner Name'
SELECT PARSENAME('pubs..authors', 3) AS 'Database Name'
SELECT PARSENAME('pubs..authors', 4) AS 'Server Name'

Here is the result set:

Object Name                    
------------------------------ 
authors                        

(1 row(s) affected)

Owner Name                     
------------------------------ 
(null)                         

(1 row(s) affected)

Database Name                  
------------------------------ 
pubs                           

(1 row(s) affected)

Server Name                    
------------------------------ 
(null)                         

(1 row(s) affected)

See Also

ALTER TABLE

CREATE TABLE

System Functions

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft