• scarlam (10/24/2012)


    Any ideas on how to go about writing a script or stored procedure that can loop through this table.

    You're a programmer, you work to a specification - or if you are unlucky, a verbal brief. You can do anything, provided that the explanation is correct, complete, and clear.

    The specification you've provided us with is none of these. Nobody can do anything for you yet. Go back and fill in the missing information. Without it, folks can only guess.

    Use this as your sample data and refer to it in your explanation:

    ;WITH SampleData (Serial, PartID, Amount) AS (

    SELECT 'VC8', 'PC545', '4,474.23' UNION ALL

    SELECT 'VC00', '586', '225.00' UNION ALL

    SELECT 'VC00', '516', '2,550.00' UNION ALL

    SELECT 'VC00', '421', '40.00' UNION ALL

    SELECT 'VC9', '277', '19.23' UNION ALL

    SELECT 'VC00', '815', '1,620.00' UNION ALL

    SELECT 'vc00', '206', '20.00' UNION ALL

    SELECT 'VC1', '133', '348.76' UNION ALL

    SELECT 'VC9', '436', '75.00' UNION ALL

    SELECT 'VC9', '534', '273.76' UNION ALL

    SELECT 'VC1', '133', '945.25' UNION ALL

    SELECT 'VC9', '854', '945.25' UNION ALL

    SELECT 'VC1', '826', '40.00' UNION ALL

    SELECT 'VC8', '147', '40.00' UNION ALL

    SELECT 'VC1', '754', '5,131.70' UNION ALL

    SELECT 'VC4', 'PC545', '3,101.70' UNION ALL

    SELECT 'VC9', '978', '2,030.00')

    SELECT Serial, PartID, Amount = CAST(REPLACE(Amount,',','') AS DECIMAL(8,2))

    FROM SampleData

    --WHERE Serial IN ('VC1','VC8')

    ORDER BY Serial, PartID


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]