• Maverick, I found this one example. You can ignore the fields in the SELECT statement up to the ,N. The important code for you is the part that breaks up StuGrades, which is the pipe delimited field. Hope this helps you!

    --===== Add a Primary Key to maximize performance

    ALTER TABLE dbo.Tally

    ADD CONSTRAINT PK_Tally_N

    PRIMARY KEY CLUSTERED (N) WITH FILLFACTOR = 100

    --===== Expand the grades in GBStudents

    IF OBJECT_ID('dbo.PKgrades') IS NOT NULL

    DROP TABLE dbo.PKgrades

    --===== Fix GBStudents for cases where end character is not "|"

    UPDATE GBStudents

    SET StuGrades = RTRIM(StuGrades) + '|'

    WHERE StuGrades<>' '

    AND RIGHT(RTRIM(StuGrades),1) <> '|'

    --===== Get the fields we need and use the Tally table to break the delimiters

    SELECT STUSchoolYear AS PKGSchoolYear

    ,STUSchoolID AS PKGSchoolID

    ,STUTeacherID AS PKGTeacherID

    ,STUCycle AS PKGCycle

    ,STUSheet AS PKGSheet

    ,STUSchoolID AS PKGId

    ,STUStudentID AS PKGStudentID

    ,STULName AS PKGLName

    ,STUFName AS PKGFName

    ,STUMName AS PKGMName

    ,STUGradeLevel AS PKGGradeLevel

    ,STUSection AS PKGSection

    ,STUPeriod AS PKGPeriod

    ,N

    ,SUBSTRING('|'+StuGrades,N+1,CHARINDEX('|','|'+StuGrades,N+1)-N-1) AS PKGGrade

    ,ROW_NUMBER() OVER (ORDER BY STUSchoolYear --==== Row numbers will create the AsgId

    ,STUSchoolID

    ,STUTeacherID

    ,STUCycle

    ,STUSheet

    ,STUStudentID

    ,N) AS RowNum

    INTO PKgrades

    FROM dbo.Tally t

    CROSS JOIN GBStudents

    WHERE N < LEN('|'+StuGrades)

    AND SUBSTRING('|'+StuGrades,N,1) = '|'