case statement based on another column

San 161 Reputation points
2023-08-02T10:25:56.7566667+00:00

Dear experts,

based on the below data, Instead of updating data. I want to handle these in case statements.

IF CODE= SMG_TH/N then show type_num=2 instead of 1

User's image

SQL Server | Other
0 comments No comments
{count} votes

Answer accepted by question author
  1. Viorel 125.8K Reputation points
    2023-08-02T11:15:17.84+00:00

    Try:

    select ROW_ID, CODE, case when CODE = 'SMG_TH/N' and TYPE_NUM = 1 then 2 else TYPE_NUM end as TYPE_NUM
    from MyTable
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.