Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

MSSQL insert If statement for less than / equal to

Options
  • 11-08-2015 2:59pm
    #1
    Moderators, Category Moderators, Music Moderators, Politics Moderators, Society & Culture Moderators Posts: 22,360 CMod ✭✭✭✭


    Hi All,

    Apologies if this may sound a bit backwards. I'm more used to setting up a query in excel.

    I have a column with an integer and a column in another table that I want to have a "Pass" / "Fail" value input based on passing when the integer is less than or equal to 15.

    However I'm not getting any luck when finding anything to do this. They all tend to be select statements to present the data. I want it to be a result inserted into a row matching a Ticket ID.

    I have the merge criteria for this fine. It's just when trying to fill in the blanks left over and trying to insert a Pass/Fail result I'm getting a bit lost.

    Any advice would be much appreciated.


Comments

  • Registered Users Posts: 772 ✭✭✭pillphil


    UPDATE table_name
    SET CASE
    WHEN oneThing_Column > anotherThing THEN (pass/fail_column = 'pass')
    WHEN oneThing_Column <= anotherThing THEN (pass/fail_column = 'fail')

    END
    WHERE TicketId=some_value

    Something like that? I'm learning sql so that may not be remotely right


  • Registered Users Posts: 772 ✭✭✭pillphil


    Actually, more like this

    UPDATE tableName
    SET Column_Name = CASE WHEN Ticket_ID <= 15 THEN 'pass' ELSE 'fail' END
    Where Ticket_ID = desiredTicket_ID;


  • Moderators, Category Moderators, Music Moderators, Politics Moderators, Society & Culture Moderators Posts: 22,360 CMod ✭✭✭✭Dravokivich


    Thanks lads. I'll try that out in the morning.


  • Moderators, Category Moderators, Music Moderators, Politics Moderators, Society & Culture Moderators Posts: 22,360 CMod ✭✭✭✭Dravokivich


    pillphil wrote: »
    Actually, more like this

    UPDATE tableName
    SET Column_Name = CASE WHEN Ticket_ID <= 15 THEN 'pass' ELSE 'fail' END
    Where Ticket_ID = desiredTicket_ID;

    Thanks, that did the trick!

    :)


Advertisement