title | description | author | ms.author | ms.date | ms.service | ms.subservice | ms.topic | f1_keywords | helpviewer_keywords | dev_langs | monikerRange | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parse (Database Engine) |
Parse (Database Engine) |
MikeRayMSFT |
mikeray |
07/22/2017 |
sql |
t-sql |
reference |
|
|
|
=azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current ||=fabric |
[!INCLUDE SQL Server Azure SQL Database Azure SQL Managed Instance FabricSQLDB]
Parse converts the canonical string representation of a hierarchyid to a hierarchyid value. Parse is called implicitly when a conversion from a string type to hierarchyid occurs. Acts as the opposite of ToString. Parse() is a static method.
-- Transact-SQL syntax
hierarchyid::Parse ( input )
-- This is functionally equivalent to the following syntax
-- which implicitly calls Parse():
CAST ( input AS hierarchyid )
-- CLR syntax
static SqlHierarchyId Parse ( SqlString input )
input
[!INCLUDEtsql]: The character data type value that is being converted.
CLR: The String value that is being evaluated.
SQL Server return type:hierarchyid
CLR return type:SqlHierarchyId
If Parse receives a value that is not a valid string representation of a hierarchyid, an exception is raised. For example, if char data types contain trailing spaces, an exception is raised.
The following code example uses ToString
to convert a hierarchyid value to a string, and Parse
to convert a string value to a hierarchyid.
DECLARE @StringValue AS NVARCHAR(4000), @hierarchyidValue AS hierarchyid
SET @StringValue = '/1/1/3/'
SET @hierarchyidValue = 0x5ADE
SELECT hierarchyid::Parse(@StringValue) AS hierarchyidRepresentation,
@hierarchyidValue.ToString() AS StringRepresentation ;
GO
[!INCLUDEssResult]
hierarchyidRepresentation StringRepresentation
------------------------- -----------------------
0x5ADE /1/1/3/
The following code snippet calls the Parse() method:
string input = "/1/2/";
SqlHierarchyId.Parse(input);
hierarchyid Data Type Method Reference
Hierarchical Data (SQL Server)
hierarchyid (Transact-SQL)