Skip to content

Latest commit

 

History

History
99 lines (79 loc) · 3.09 KB

File metadata and controls

99 lines (79 loc) · 3.09 KB
title Parse (Database Engine) | Microsoft Docs
ms.custom
ms.date 7/22/2017
ms.prod sql-non-specified
ms.prod_service database-engine, sql-database
ms.service
ms.component t-sql|data-types
ms.reviewer
ms.suite sql
ms.technology
database-engine
ms.tgt_pltfrm
ms.topic language-reference
f1_keywords
Parse
Parse_TSQL
dev_langs
TSQL
helpviewer_keywords
Parse [Database Engine]
ms.assetid b37e28b6-6e2e-470a-945b-ce5252da743a
caps.latest.revision 17
author edmacauley
ms.author edmaca
manager craigg
ms.workload Inactive

Parse (Database Engine)

[!INCLUDEtsql-appliesto-ss2012-asdb-xxxx-xxx-md]

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.

Syntax

-- 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 )   

Arguments

input
[!INCLUDEtsql]: The character data type value that is being converted.

CLR: The String value that is being evaluated.

Return Types

SQL Server return type:hierarchyid

CLR return type:SqlHierarchyId

Remarks

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.

Examples

A. Converting Transact-SQL values without a table

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/

B. CLR example

The following code snippet calls the Parse() method:

string input =/1/2/”;  
SqlHierarchyId.Parse(input);  

See also

hierarchyid Data Type Method Reference
Hierarchical Data (SQL Server)
hierarchyid (Transact-SQL)