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
('6.0.0.0'),('3.0.0.0'),('4.5.1.0'),('4.5.8.0'),('4.5.11.0'),('1.1.2.14234'),('1.11.21.14234'),('1.8.2.14234'),('6.0.0.1')

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

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

The answer is

        Version

--------
1.1.2.14234
1.8.2.14234
1.11.21.14234
3.0.0.0
4.5.1.0
4.5.8.0
4.5.11.0
6.0.0.0
6.0.0.1

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