need help for sql query

  • hi all ,

    i need to addition to column which i given below.

    SELECT

    CASE

    WHEN UPPER(f.newact) = 'N'

    THEN c.numberofleavesnew

    WHEN UPPER(f.newact) = 'R'

    THEN c.numberofleaves

    END AS Number_of_Leaves

    , f.STRT_SER

    FROM finacle_upload_detail AS f INNER JOIN cheque_master AS c ON c.schemecode = f.schcd.

    getting result.

    ----------------------

    numberofleaves STRT_SER

    50 12300

    25 45200

    30 14522

    i need to addition this two column kindly need help

    Thanks\

    Rajnidas

  • Unless your database is case-sensitive, you don't need the UPPERs.

    Also you should always qualify your tables with their schema.

    So I've rewritten your query a little to account for the above.

    with Sub1

    as (

    select Number_of_Leaves = (

    case

    when f.newact = 'N'

    then c.numberofleavesnew

    when f.newact = 'R'

    then c.numberofleaves

    end

    )

    ,f.STRT_SER

    from dbo.finacle_upload_detail f

    join dbo.cheque_master c on c.schemecode = f.schcd

    )

    select s.Number_of_Leaves

    ,s.Strt_Ser

    ,Tot = s.Number_of_Leaves + s.Strt_Ser

    from Sub1 s

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Phil Parkin (8/5/2014)


    Unless your database is case-sensitive, you don't need the UPPERs.

    Also you should always qualify your tables with their schema.

    And you should finish your statements with the semicolon operator. 😉

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Koen Verbeeck (8/5/2014)


    Phil Parkin (8/5/2014)


    Unless your database is case-sensitive, you don't need the UPPERs.

    Also you should always qualify your tables with their schema.

    And you should finish your statements with the semicolon operator. 😉

    Hah, yes! 🙂

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

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

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