Write (Database Engine)

Applies to: yesSQL Server (all supported versions) YesAzure SQL Database

Write writes out a binary representation of SqlHierarchyId to the passed-in BinaryWriter. Write cannot be called by using Transact-SQL. Use CAST or CONVERT instead.


void Write( BinaryWriter w )


To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.


A BinaryWriter object to which the binary representation of this hierarchyid node will be written out.

Return Types

CLR return type:void


Write is used internally by SQL Server when it is necessary, such as when loading data from a hierarchyid column. Write is also called internally when a conversion is done between hierarchyid and varbinary.


MemoryStream stream = new MemoryStream();  
BinaryWriter bw = new BinaryWriter(stream);  
byte[] encoding = stream.ToArray();  

See also

Read (Database Engine)
ToString (Database Engine)
CAST and CONVERT (Transact-SQL)
hierarchyid Data Type Method Reference