Results 1 to 3 of 3

Thread: More Query Help

  1. #1

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    More Query Help

    Right i've ran into another problem

    in my table i have the following columns:
    i=integer, b=bit, m=smallmoney
    Code:
    iNoCoachMovements , bChargePerCoach, mCoachFee
    3,                            1,                       50.00
    3,                            0,                       100.00
    0,                            0,                       100.00
    so i need to perform a query on the details above.
    the way it will work is that
    Code:
    if bChargePerCoach = 1 then 
        iNoCoachMovements * mCoachFee
    elseif iNoCoachMovements > 0 Then
          mCoachFee
    else 0
    end if
    is this possible in a SQL Query.

    it works for the 1st part with the sql below:
    Code:
     SUM(CASE WHEN (dbo.tbl_Contracts.bChargePerCoach = 1) THEN (dbo.tbl_Despatches.iNoCoachMovements * dbo.tbl_Contracts.mCoachFee) 
                          ELSE 0 END)
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: More Query Help

    You can have multiple WHEN clauses, eg:
    Code:
    SUM(
      CASE 
        WHEN (dbo.tbl_Contracts.bChargePerCoach = 1) THEN (dbo.tbl_Despatches.iNoCoachMovements * dbo.tbl_Contracts.mCoachFee) 
        WHEN (dbo.tbl_Contracts.iNoCoachMovements > 0) THEN (dbo.tbl_Contracts.mCoachFee)
      ELSE 0 
      END
    )

  3. #3

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: More Query Help

    si what can i say man... but legend... cant believe i missed that

    cheers again
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width