How to query a condition on a single object of sql record?



  • I'll try my best to explain the situation here. We are using MariaDB.

    In certain case we are looping over all the records/rows of a REQUESTS table. and for each object/record we are checking few conditions and if condition passes we are performing an action. All the said things here are being done using ruby. Say I want to check the same on pure SQL, I wanted to see how.

    Sample Object a Request table:

    [{"ot_rqst_id":27460354,"rqst_type_cd":"NONTP","svc_type_cd":"TD","sl_ttl_type_cd":"","lot_num":41843022, ttl_stg_cd: 'CMPLT'}]
    

    What I want to check on sql: To see if the ttl_stg_cd of this object is equal to 'CMPLT'. If it is then update it to NULL else "something_else".

    Let me remind you again that, I am already doing this in ruby language, but I am not an expert on sql so help would be appreciated.



  • For all rows in the table it would be an https://mariadb.com/kb/en/update/ , like the following:

       UPDATE Requests
       SET ttl_stg_cd = IF(ttl_stg_cd = CMPLT, NULL, "something else")
    

    Assuming your notation is referring to a table with rows and not just a json blob in a row.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2