Is it possible to write a SQL Statement as follows

  • My Data looks like this:

    FormulaID VersionID MaterialID WantedCol

    123 .1 2222 1

    123 .1 3333 2

    123 .1 4444 3

    123 .5 2222 1

    123 .5 3333 2

    123 .5 5555 3

    123 .5 8888 4

    199 .1 1111 1

    .....

    My current select statement is simply:

    Select FormulaID, VersionID, MaterialID From tblFormula Order By FormulaID, VersionID, MaterialID.

    So is there a way with a select statement to gain the WantedCol without using a cursor.

    I want to add a column that will contain the sort order per formula/version.

    Is this possible???

    Any help will be appreciated!

  • I figured it out in case anyone is wondering

    This SQL Statement does the trick.

    Select FormulaID, VersionID, MaterialID, TypeID, MixOrder,

    (SELECT COUNT(*) FROM formula_material f WHERE f.FormulaID = f_m.FormulaID and f.VersionID = f_m.VersionID ANd f.MaterialID <= f_m.MaterialID) AS RNUM

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply