Skip to content
Advertisement

SQL query based on column condition

I have a sql table in which below are the columns. I’m using sql server.

Id, name, device and information on if device is active or not.

Need to have a SQL query for below scenario:

I want to display firstdevice, seconddevice columns below based on isActive column. If isACTIVE is 1 then, fill the device name in firstdevice column, if isActive is 0 then fill the device name in secondDevice.

Id name firstDevice secondDevice
1 Motorola phone tablet

Advertisement

Answer

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement