Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7860605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:21:34+00:00 2026-06-02T22:21:34+00:00

I have many columns in a table which needs to be checked against some

  • 0

I have many columns in a table which needs to be checked against some value and values needs to be replaced if match found..

So basically I am looking for a query which takes column name as sort of variable and loops through the table and updates the column value if matched..

I could do that with php, having as many queries as columns.. but that’s what I don’t want..

p.s. I know its a bad design, and in normal case such requirements never occur, but sadly it is what it is..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:21:35+00:00Added an answer on June 2, 2026 at 10:21 pm

    In many statements:

    UPDATE tableX 
    SET   col_1 = 'newvalue' 
    WHERE col_1 = 'ram';
    
    UPDATE tableX 
    SET   col_2 = 'newvalue' 
    WHERE col_2 = 'ram';
    
    ...
    
    UPDATE tableX 
    SET   col_N = 'newvalue' 
    WHERE col_N = 'ram';
    

    In one statement

    UPDATE tableX 
    SET   col_1 = CASE WHEN col_1 = 'ram'
                         THEN 'newvalue' 
                         ELSE col_1 
                  END
        , col_2 = CASE WHEN col_2 = 'ram'
                         THEN 'newvalue' 
                         ELSE col_2 
                  END
        ...
    
        , col_N = CASE WHEN col_N = 'ram'
                         THEN 'newvalue' 
                         ELSE col_N 
                  END
     ;
    

    You can write the statements by hand or with dynamic SQL (if the columns and tables to work are too many).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very big table with many columns. Values in some of the
i have made a gridview which has many columns and the editmode , some
I have a table, which contains many columns of float data type with 15
I have a table with many columns among which I'd like to omit a
I have many columns in oracle database and some new are added with values.
I have a fixed width DIV containing a table with many columns, and need
I have a table of product information with many bit columns. This table can
I am having a HTML table with many rows. I have seven columns in
I have a table of many values where one column has the WO Number,
I have a table called 'customer' which has too many rows & the decision

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.