Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Towards the innovative SQL ideas
Browse by Tags · View All
ms sql server 119
ms sql 118
sql server 116
sql 115
database 102
tsql 81
#SQL Server 78
t-sql 75
#sql 71
sql server general 67

Archive · View All
April 2011 14
July 2011 12
May 2011 12
August 2011 11
June 2011 10
September 2011 8
December 2011 6
November 2011 6
June 2013 5
April 2013 5

HierarchyId DataType in SQL Server 2008 - Get Level and String Path

Jun 26 2011 5:39AM by Paresh Prajapati   

In previous post I have published of the overview of HierarchyId data type. In this post I am writing about details and the methods with hierarchy with HierarchyId data type.

Before go ahead with this post, please read the previous post here. The example which I am going to demonstrate HierarchyId and the methods for the same will drive you in details and towards of better understanding.

Let’s create database and table objects.
-- Create database and table
CREATE DATABASE HierarchyDB

GO

USE HierarchyDB

GO

IF ( Object_id('HierarchyTab') > 0 )
DROP TABLE HierarchyTab

GO

CREATE TABLE HierarchyTab
(
NodeId     INT IDENTITY(1, 1)
,NodeDepth VARCHAR(100) NOT NULL
,NodePath  HIERARCHYID NOT NULL
,NodeDesc  VARCHAR(100)
)

GO 

-- Creating constraint on hierarchy data type.
ALTER TABLE HierarchyTab ADD CONSTRAINT U_NodePath UNIQUE CLUSTERED (NodePath)

GO 
Now inserting some sample records of hierarchical data.
-- Inserting data in above creatd table.
INSERT INTO HierarchyTab(NodeDepth,NodePath,NodeDesc)
VALUES 
('1',HIERARCHYID::Parse('/'),'Node-1'),
('1.1',HIERARCHYID::Parse('/1/'),'Node-2'),
('1.1.1',HIERARCHYID::Parse('/1/1/'),'Node-3'),
('1.1.2',HIERARCHYID::Parse('/1/2/'),'Node-4'),
('1.2',HIERARCHYID::Parse('/2/'),'Node-5'),
('1.2.1',HIERARCHYID::Parse('/2/1/'),'Node-6'),
('1.2.2',HIERARCHYID::Parse('/2/2/'),'Node-7'),
('1.2.2.1',HIERARCHYID::Parse('/2/2/1/'),'Node-8'),
('1.2.2.1.1',HIERARCHYID::Parse('/2/2/1/1/'),'Node-9'),
('1.2.2.1.2',HIERARCHYID::Parse('/2/2/1/2/'),'Node-10'),
('1.3',HIERARCHYID::Parse('/3/'),'Node-11'),
('1.3.1',HIERARCHYID::Parse('/3/1/'),'Node-12'),
('1.3.2',HIERARCHYID::Parse('/3/2/'),'Node-13'),
('1.4',HIERARCHYID::Parse('/4/'),'Node-14')

GO
Here is the logical image for the above data are as following,

HierarchyId-1

Now we will look for the some of the methods of HierarchyId data type. We will go through GetRoot, ToString, Parse and GetLevel methods here and demonstrate in details for each.

Let's drive with me here. Before please my earlier post of overview of such methods here.

1. GetRoot()
-- GetRoot()
SELECT 
HIERARCHYID::GetRoot() AS RootNode
,HIERARCHYID::GetRoot().ToString() AS RootNodePath

GO
RootNode   RootnodePath 0x                /

2. ToString()
-- ToString()
SELECT
NodePath.ToString() AS NodeStringPath
,NodeId
,NodeDepth
,NodePath
,NodeDesc
FROM   HierarchyTab

GO 
GetString

3. Parse()
-- Parse()
SELECT
HIERARCHYID::Parse(NodePath.ToString()) AS NodeVarBinaryPath,
NodePath.ToString() AS NodeStringPath,
NodeId,
NodeDepth,
NodePath,
NodeDesc
FROM HierarchyTab

GO
Parse

4. GetLevel()
-- GetLevel()
SELECT 
NodePath.GetLevel() AS NodeLevel,
NodePath.ToString() AS NodeStringPath,
NodeId,
NodeDepth,
NodePath,
NodeDesc
FROM HierarchyTab

GO
Level

Now you have a very good idea and understanding for HierarchyId data type after reading this post. You can also read the Hiercrchyd Datatype Overview.

I will write next future post for other methods of HierarchyId data type.   

Tags: sql, sql server 2008, tsql, sql server, ms sql, ms sql server, t-sql, #SQL Server, mssql, #sql, database, sql server general, SQL Scripts, SQL new features,


Paresh Prajapati
6 · 22% · 7044
4
 
0
Lifesaver
 
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"HierarchyId DataType in SQL Server 2008 - Get Level and String Path" rated 5 out of 5 by 4 readers
HierarchyId DataType in SQL Server 2008 - Get Level and String Path , 5.0 out of 5 based on 4 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]