need update statement (Asked by Microsoft) | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

need update statement (Asked by Microsoft)

Hello All,
The following one was asked to me in Microsoft interview.
Suppose there is a table with the following data Table Name : Door
———————-
Door_Id Door_Status
========================
1 0
2 0
3 1
4 1
5 1
6 0
7 1
8 1
9 0
10 1 —



Question:
===============
We have to update the table such a way if Door_id = 1 it can update all the record. For door_id =1 it can update all the records
For door_id =2 it can update record no: 2,4,6,8,10 the records
For door_id =3 it can update record no: 3,6,9 the records
For door_id =4 it can update record no: 4,8 the records
For door_id =5 it can update record no: 5,10 the records
For door_id =6-10 it can update only one record which is equivalent to corresponding
record no. so for example if door_id=2 I need to update row no 2,4,6,8 & 10 for door_status.
if door_status is 0 make it to 1 or if it is 1 make it 0. How to do that in a single update statement?? Need all of your utmost help. Regards
Niladri
If the question is coming from Microsoft, and you’re supposed to answer it – why are you asking us?
Agree with Adriaan and locked.
Luis Martin
Moderator
SQL-Server-Performance.com Although nature commences with reason and ends in experience it is necessary for us to do the opposite, that is to commence with experience and from this to proceed to investigate the reason.
Leonardo Da Vinci Nunca esperes el reconocimiento de tus hijos, eso ocurrirá luego de tu muerte
All postings are provided “AS IS” with no warranties for accuracy.
]]>