SQL Interview Questions/Updating 0 as 1 and 1 as 0 : 2

2. updating quantity 0 as 1 and 1 as 0 in a product table

create table product

(

name varchar(100),

quantity int

)

insert into product values('laptop',1) ,('mobile',0)

select * from product

Input Table:-

                              




method1:- 

UPDATE product SET quantity=1-quantity

output:-          


method2:-

SELECT  name,quantity=(SELECT CASE WHEN quantity=1 THEN 0 ELSE 1 END) FROM product

output:-



method3:-

3)UPDATE quantity SET quantity=CASE WHEN quantity=1 THEN 0 ELSE 1 END FROM  product

Output :-

                                     


Comments

Popular posts from this blog

SQL Interview Questions:3

AZURE DATA FACTORY INTERVIEW QUESTIONS: FILES FORMATS

AZURE DATA FACTORY INTERVIEW QUESTIONS :ACTIVITIES AND TYPES.