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 8275105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:57:50+00:00 2026-06-08T07:57:50+00:00

I need to update the next column to the column that contains an specific

  • 0

I need to update the next column to the column that contains an specific number.

The ff are columns in the table C.

C1_K | C1_ID | C2_K | C2_ID | C3_K | C3_ID

Logic:

  • Look for where number 5 is found is it in C1_K OR C2_K OR C3_K.
  • If it is in C1_K then select the text value C1_ID.
  • If it is in C2_K then select the text value C2_ID.
  • If it is in C3_K then select the text value C3_ID.

Please advice. I need to update the column next to the matching K column. Thanks.

Note:

  • All C*_K columns contains unique numbers.
  • All C*_ID columns contains unique text. (these are names)

Sample Data:

 154 | NULL | 155 | SantoRyUu | 156 | NULL

If 155 is chosen SantoRyUu will be updated.

  • 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-08T07:57:51+00:00Added an answer on June 8, 2026 at 7:57 am

    (Design problems aside.)

    You have to mention the columns by name, since SQL Server doesn’t have syntax for “next to.” You may be able to do this with dynamic SQL, but yuck. Here is one possibility:

    CREATE TABLE dbo.C
    (
      C1_K  INT, 
      C1_ID VARCHAR(32), 
      C2_K  INT, 
      C2_ID VARCHAR(32), 
      C3_K  INT, 
      C3_ID VARCHAR(32)
    );
    
    INSERT dbo.C(C1_K, C2_K, C3_k)
    SELECT 5,1,2
    UNION ALL SELECT 2,5,7
    UNION ALL SELECT 3,4,6;
    
    DECLARE @MagicNumber INT;
    SET @MagicNumber = 5;
    
    UPDATE dbo.C SET 
     C1_ID = CASE C1_K WHEN @MagicNumber THEN 'yes' ELSE C1_ID END,
     C2_ID = CASE C2_K WHEN @MagicNumber THEN 'yes' ELSE C2_ID END,
     C3_ID = CASE C3_K WHEN @MagicNumber THEN 'yes' ELSE C3_ID END;
    
    SELECT * FROM dbo.C;
    

    Results:

    C1_K  C1_ID  C2_K  C2_ID  C3_K  C3_ID
    ----  -----  ----  -----  ----  -----
    5     yes    1     NULL   2     NULL
    2     NULL   5     yes    7     NULL
    3     NULL   4     NULL   6     NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to update the Notes field in my table tblMain by concatenating the
I need to update an Attributes column in an MSI file. Unfortunately, I am
I need to update millions of rows as part of my next release, but
I need to add a select box next to each field in a create/update
If i had this column: ColA ----- NUMBER(8,3) NUMBER(20) I need a VBA function
I have a Datagridview that contains few columns and data in each row. I
I need to update my .htaccess file to redirect permanently all URLs from http://example.com/pages/5604/article/something/?page=299
I need to update time info in a DateTime. I get a string in
I need to update a json list of object via url post data. For
I need to update a form in AX to use a complex drop down

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.