• Lynn,

    you were right, I should have provided descriptons as what I am tryin gto do. Here is the when running the query:

    Name1Name2Total

    X1 Y1 8

    X2 Y2 38

    X3 Y3 2

    X4 Y4 29

    X4 Y5 18

    X4 Y6 7

    X4 Y7 10

    X5 Y8 4

    X5 Y9 80

    X5 Y10 32

    X5 Y11 93

    X6 Y12 54

    X6 Y13 22

    X6 Y14 68

    X7 Y15 6

    X7 Y16 9

    X7 Y17 100

    X8 Y18 3

    FIrst I need to populate Column D with 0 or 1 if:

    sum of Total (column C) over Name1 > 100 and Total for name2 < 25 then =1 otherwise = 0

    I accomplished that by:

    case when (sum(total) over (partition by name1) >100) and total <25 Then 1

    else 0

    end as [Name1>100&Name2<25],

    Second, I need to same thing as above except that the sum is < 100. I accomplished that by:

    case when (sum(total) over (partition by name1) <100) and total <25 Then 1

    else 0

    end as [Name1<100&Name2<25],

    Third, I need to assign (1 or 0) is:

    sum of Total over Name1 > 100 and min of Total < 25 then 1 otherwise 0. What I need here, take records for X7:

    X7 Y15 6

    X7 Y16 9

    X7 Y17 100

    The sum of Total is > 100 but I need to assign value of 1 only for first record (X7 Y15 6) and 0 for the rest of record. THe query I posted for this doesn't work and assign value of 1 for all the records despite I had min.

    and the last scenario, is just the opposite of the latter with sum < 100. Thus desired outcome for X7 for all scenarios will be:

    name1name2totalsum>100&Total<25 sum<100&Total<25 sum>100&minTotal<25 sum>100&minTotal<25

    X7Y156 1 0 1 0

    X7 Y16 9 1 0 0 0

    X7 Y17 100 0 0 0 0

    and for X4 records:

    name1name2totalsum>100&Total<25 sum<100&Total<25 sum>100&minTotal<25 sum>100&minTotal<25

    X4Y429 0 0 0 0

    X4 Y5 18 0 1 0 0

    X4 Y6 7 0 1 0 1

    X4 Y7 10 0 1 0 0

    again, the case when functions I posted are working correctly to populate Columns D&E but not for F&G. I hope this helps.