I am beginner at SQL. I am doing research about managing hierarchical data by using ms sql r2 2008. Here is the link from where I referred
http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/
But now I having a problem in Finding the Depth of the Nodes
I Copy the sql query to my ms sql
SELECT CONCAT( REPEAT(' ', COUNT(parent.name) - 1), node.name) AS name
FROM nested_category AS node, nested_category AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
GROUP BY node.name
ORDER BY node.lft;
It return me
Msg 195, Level 15, State 10, Line 1 ‘REPEAT’ is not a recognized built-in function name.
Can anyone please help me correct the sql query?
In addition, anyone got a better solution for manage hierarchical data?
You using code from a MySQL article on MS SQL Server.
Much will translate fine, but much won’t. As @FilipDeVos says, the equivilent to
REPEAT()in SQL Server isREPLICATE(), and you’re going to find many more cases like this.When you find them, you need to search on line for the SQL Server equivilent to the MySQL statements that you are using.
As for different methods of managing hierarchies, the most common is probably adjaceny-lists, then nested-sets that you’re using in that article. It depends on your needs, keep researching, there is no universall golden answer.
EDIT
If you keep going through that article and ask here about every difference, you’ll be here forever. You need to search the web for your answers 😉
But, for now, after your added question about
CONCAT(), try this…