What will be the output of

--Input Script
--Declare a sample table variable
DECLARE @tblAssemblyVersion TABLE(Version VARCHAR(20))

--Insert some records to it
INSERT INTO @tblAssemblyVersion VALUES

SELECT * FROM @tblAssemblyVersion
ORDER BY CAST('/'+REPLACE(Version,'.','/')+'/' AS hierarchyID)

 Posted by Rajnilari2015 on 3/20/2017 | Category: Sql Server Interview questions | Views: 2688 | Points: 40

The answer is



The hierarchyid data type values represents a position in a tree hierarchy and it performs Depth-first search of the tree traversal.That indicates that for any two hierarchy id values e.g. x and y, if x and y are in a relationship of x<y, then in the case of Depth-first search, x will always appear before y. And hence the answer.

| Alert Moderator 

Comments or Responses

Login to post response