Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I think this forum rocks it has saved my bacon many many times..."

Geography

Where in the world do Tek-Tips members come from?
rotaxmax12 (TechnicalUser)
3 Aug 12 18:13
I have to migrate data from one table to a master table that uses HierarchyID data types. I can establish the parent, but I am not sure of the SQL syntax to be able to find the next node based on the parent.

I used this to initially seed the database:
WITH updateHID AS
(SELECT struct.Id AS TranID
, struct.Parent_Parent AS TranParent
, struct.Parent_Hid AS oldHID
, CAST(CONVERT(varchar(20),tranLine.Parent_Hid.ToString()) + CONVERT(varchar(20),row_number() over(partition by struct.Parent_Parent ORDER BY struct.Parent_Parent)) + '/' as hierarchyid) AS newHID
FROM dbo.Asset AS struct
JOIN dbo.Asset AS tranLine ON struct.Parent_Parent = tranLine.Id
WHERE tranLine.AssetType = 'D76AF6C7-9A0F-4A7C-BE0C-3A429976C2F7'
AND struct.AssetType IN ('924A8376-35B6-4CA9-B326-FCB6D31E5B7F','3C8C74E5-1492-497E-AA1D-9920E424F765') )
UPDATE updateHID
SET oldHID = newHID

I just need to know how to have this script/stored procedure going forward that it will get the max node for each parent.

Thanks

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close