SQL script for updating column

  • Hi Guys

    I'm new here and quite new to SQL so be gentle please!

    I need to place a number in a column in our database (cu_bank_analys) for all our customers which have criteria (cuuser = 274) The column is not populated at present and i have several hundred to put this number into.

    Just wanted to run the script by you guys to see if it looks ok and wont corrupt anything.

    The script below brings me up all the info i need and all looks good but just wanted to check.

    Thanks

    use testdb

    select CU_BANK_ANALYS FROM sl_accounts

    WHERE CUUSER2 = '274'

    UPDATE SL_ACCOUNTS SET CU_BANK_ANALYS = 24011410

  • If you want to update CU_BANK_ANALYS for all rows that has CUUSER2 as 274, you have to use the Where clause. Right now you are doing a blind update. You will update all rows.

    UPDATE SL_ACCOUNTS

    SET CU_BANK_ANALYS = 24011410

    WHERE CUUSER2 = '274'

    If that is not what you wanted to do, please do explain to us. Someone will help you.

    -Roy

  • Hi Roy and thanks for the repsonse.

    Excuse my ignorance but what do you mean "a blind update" ?

    I want to insert this number in 'column cu_bank_analys' for all rows (Customers) which have the number 274 in field "cuuser".

    Hope this makes sense

  • Blind update is when you are updating all rows in the table without any condition. No WHERE CLAUSE.

    The update I gave you will work. It will update CU_BANK_ANALYS with the data you provided for all rows that has CUUSER2 as 274.

    But before you do an update check it out by doing a select statement.

    Select CUUSER2,CU_BANK_ANALYS from SL_ACCOUNTS

    WHERE CUUSER2 = '274'

    If the rows returned by running this query are what you want to update then you can run the update statement I gave you previously.

    -Roy

  • Ok i understand now regarding blind.

    The help is just what i was after Roy, thanks very much its really appreciated.

    Have a great day!

    Tone

Viewing 5 posts - 1 through 5 (of 5 total)

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