Note that there are some explanatory texts on larger screens.

plurals
  1. POMigrating categories using SQL OUTPUT
    primarykey
    data
    text
    <p>I want to do something like</p> <pre><code>DECLARE @idTable TABLE ( hierakiId INT, katId INT ); DECLARE @id int SET @id = (SELECT MIN([ID]) FROM [Hieraki] WHERE Navn = 'Sagsskabeloner') INSERT INTO HierakiMedlem(Navn, HierakiID) OUTPUT INSERTED.ID, s.ID INTO @idTable SELECT s.Navn, @id, s.ID FROM SagSkabelonKategori s UPDATE s SET s.HierakiMedlem = @idTable.hierakiId FROM SagSkabelon s INNER JOIN @idTable ON s.SagSkabelonKategoriID = @idTable.katId </code></pre> <p>resulting in a map in @idTable, mapping the old to the new identity of each category, so that i can change references as needed. Obviously this results in an error (3rd line) as the SELECT results in more columns than used by the INSERT INTO. </p> <p>Any suggestions on the cleanest way to do this?</p> <hr> <p>I'm on SQL Server 2005.</p> <p>/edit</p> <hr> <p>now w. complete source code.</p> <p>We are switching from a semi-flat, non-nested category sorting, to a hierachy based one. All the categories are to be copied as root level nodes in the new hierachy, and the former members of each category must have a new field set referencing the newly created root node.</p> <p>what i want to do; 1. Copy all categories to the hierachy table, setting their parent (HierakiID) to the same value.</p> <ol> <li><p>update a column in all references to the categories so they now (also) reference the hierachy nodes.</p></li> <li><p>delete references to categories</p></li> <li><p>delete categories</p></li> </ol> <p>the tricky part for me is to get a map between the category id and the hierachy id.</p> <p>/edit</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload