• I broke down and wrote it as a Cursor... Still running so I do not know if my code is correct yet... I will create a table and some dummy data in the next post.

    declare @plant as varchar(4)

    , @Resource_Code as varchar(8)

    , @Material_Number as varchar(18)

    set nocount on;

    declare i_cursor insensitive cursor

    for Select Plant, Resource_Code, Material_Number From Resource_Mat

    open i_Cursor

    while @@fetch_status = 0

    begin

    insert into trans_Matrix(Company, Plant, Resource_Code, From_Material, To_Material)

    select 'SPOR' as Company

    , Plant

    , Resource_Code

    , @Material_Number as From_Material

    , Material_Number as To_Material

    from Resource_Mat

    where @Plant = plant and @resource_code = resource_code

    end

    fetch next from i_Cursor into @Plant, @Resource_Code, @Material_Number

    close i_Cursor

    deallocate i_cursor

    set nocount off;

    go