case condition

Shambhu Rai 1,406 Reputation points
2023-06-09T13:44:15.1866667+00:00

Hi Expert,

the below is the condition

case when oid= 'Winter' then Name else 'noname'

create table table1(id varchar(30), name varchar(30), oid varchar(30))

insert into table1 values('1', 'David', 'Winter')

insert into table1 values('2', 'Hash', 'Winter')

insert into table1 values('3', 'Steve', 'Autumn')

Expected output

('1', 'David', 'Winter')

('2', 'Hash', 'Winter')

('3', 'noname', 'Autumn')

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,743 questions
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,806 questions
SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,454 questions
SQL Server Analysis Services
SQL Server Analysis Services
A Microsoft online analytical data engine used in decision support and business analytics, providing the analytical data for business reports and client applications such as Power BI, Excel, Reporting Services reports, and other data visualization tools.
1,245 questions
{count} votes

7 answers

Sort by: Most helpful
  1. GeethaThatipatri-MSFT 27,567 Reputation points Microsoft Employee
    2023-06-11T15:36:45.7833333+00:00

    Hi, @Shambhu Rai Please share additional information if the above-provided solution does not meet the expected ouput.

    Regards

    Geetha

    0 comments No comments

  2. CosmogHong-MSFT 23,246 Reputation points Microsoft Vendor
    2023-06-12T02:21:18.8+00:00

    Hi @Shambhu Rai

    Please check this query:

    SELECT id,CASE WHEN oid = 'Winter' THEN name ELSE 'noname' END AS Name,oid
    FROM table1
    

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.