• jadelola (9/10/2012)


    I hope I got it right this time 🙂

    Here's your DDL and DML adjusted so it doesn't throw an error and doesn't implicitly convert numbers as text into decimal. Run it, check the figures are what you expect, if not then amend and post back:

    --===== If the test table already exists, drop it

    IF OBJECT_ID('TempDB..#tmpCustomerAmount','U') IS NOT NULL

    DROP TABLE #tmpCustomerAmount

    CREATE TABLE #tmpCustomerAmount (

    [id] [int] IDENTITY(1,1) NOT NULL,

    AmountSold [decimal](13, 2) NULL,

    AmountLeftWith [decimal](13, 2) NULL

    )

    SET IDENTITY_INSERT #tmpCustomerAmount ON

    iNSERT INTO #tmpCustomerAmount (ID, AmountSold, AmountLeftWith)

    SELECT 1,123.00,0 UNION ALL

    SELECT 2,130000,0 UNION ALL

    SELECT 3,500.00,0 UNION ALL

    SELECT 4,700.00,577 UNION ALL

    SELECT 5,300.00, 0

    SELECT * FROM #tmpCustomerAmount


    [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]