in reply to Re: Updating database question
in thread Updating database question

Shiza
I have already gone down that road. The problem with that is that I would have to do substr(column4,0,?) to get the match. When the ENG doesn't appear in at the same spot each time, it would actually double the effort and time, hense the reason for the perl script. All this will be rolled into a automated process.
Thanks
Bobby

Replies are listed 'Best First'.
Re^3: Updating database question
by shiza (Hermit) on Jun 30, 2005 at 19:03 UTC
    How about:
    UPDATE STAGING.STAGING_PREPOUICS SET column3 = 'EN' WHERE column4 LIKE '%ENG%';
    Like I said, I'm not familiar with Sybase but I know this would work with MySQL.
      Shiza
      Ok, I will admit, I spoke to soon. I guess I've just been looking at the problem for to long today. YOu were right. Thanks,
      Bobby
        I've been there many, many times and sometimes another pair of eyes is all you need. ;) What are fellow monks for?
Re^3: Updating database question
by dragonchild (Archbishop) on Jun 30, 2005 at 19:04 UTC
    UPDATE foo SET col3 = 'EN' WHERE LOWER( col4 ) LIKE '%ENG%'
    (or LCASE or LC or whatever, depending on the function for your specific database)

    lots of options ... personally, I like the Class::DBI one. This is kinda what Class::DBI was created for.


    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
      I'll all for Class::DBI. Wouldn't the best solution be to add a handler to the class for that table:
      __PACKAGE__->set_sql(query_name_here => qq{ UPDATE __TABLE__ SET col3 = ? WHERE LOWER( col4 ) LIKE CONCAT('%', ?, '%') };
      I'm not sure if the CONCAT function would be necessary.
        If you're doing the concatenation in SQL, then it's necessary. (Note, CONCAT() is MySQL-specific. Oracle, for example, would use the || operator.)

        Yes, it's possible and probably preferable to do it that way. However, I was demonstrating how CDBI makes simple-to-conceive-of tasks simple-to-do. It's the difference between Assembler (DBI) and Perl (CDBI).


        My criteria for good software:
        1. Does it work?
        2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?