Sum of a column

  • I need the sum of a column based on an if condition.

    So I want the total number of occurances where the condition is true:

    if (len(A_TowBoat) > 0 and

    len(V_TowBoat) > 0)

    OR

    (len(A_TowBoat) = 0 and

    len(V_TowBoat) = 0)

    A_TowBoat and V_TowBoat are columns in my table.

  • Rog Saber (2/17/2011)


    I need the sum of a column based on an if condition.

    So I want the total number of occurances where the condition is true:

    if (len(A_TowBoat) > 0 and

    len(V_TowBoat) > 0)

    OR

    (len(A_TowBoat) = 0 and

    len(V_TowBoat) = 0)

    A_TowBoat and V_TowBoat are columns in my table.

    SELECT COUNT(*)

    FROM MyUnnamedTable

    WHERE (len(V_TowBoat) > 0 AND len(A_TowBoat) > 0)

    OR (len(V_TowBoat) = 0 AND len(A_TowBoat) = 0)

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • Hi,

    Sorry ignore this i got the question wrong.

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

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