Removing multiple values using if else statements? I have a program that downloads raw data from a sensor. Due to to some specifications made in the SQL code, there are values that are duplicated which needs to be deleted to maintain data integrity. 

Below is a snapshot of the dataset:


Do note that is is just a snapshot of july 10th. I have 33 other devices all of them have data dates from july 10th all the way through october. 

Is there a way for me to traverse the whole dataset and find a way to set conditional statements. For example, if there are 2 values that share the same timing, take the row that has the "1" value.

At the same time, i would like to point out that this dataset is data that is collected 24/7.
You can use the ROW_NUMBER() function to produce a windowed record ID for each row, grouped by RoomCode and Time as per this db&lt;>fiddle. 

For each of the semi-duplicate rows (where RoomCode and Time are the same but Occupancy is different) this produces an incrementing number based on occupancy in descending order (so 1 = 1 and 0 = 2).

Place this in a CTE and then inner join your table to the CTE based on all columns except Occupancy where the ROW_NUMBER() pseudo column is > 1.

Example:

;WITH DataCTE AS (
SELECT RoomCode, Occupancy, Time, DayFromDate, 
ROW_NUMBER() OVER (PARTITION BY RoomCode, Time ORDER BY Occupancy DESC) AS RN
FROM DataPoints
)

DELETE d1
FROM DataPoints d1
INNER JOIN DataCTE d2
ON d1.RoomCode = d2.RoomCode
 AND d1.Occupancy = d2.Occupancy
 AND d1.Time = d2.Time
 AND d1.DayFromDate = d2.DayFromDate
WHERE d2.RN &gt; 1


Result:

RoomCode    Occupancy   Time    DayFromDate
EW1A-03-08  0   07/10/2019 08:00:00     Wednesday
EW1A-03-08  1   07/10/2019 08:30:00     Wednesday
EW1A-03-08  1   07/10/2019 09:00:00     Wednesday
EW1A-03-08  1   07/10/2019 09:30:00     Wednesday
EW1A-03-08  1   07/10/2019 10:00:00     Wednesday
EW1A-03-08  1   07/10/2019 10:30:00     Wednesday
EW1A-03-08  0   07/10/2019 11:00:00     Wednesday
EW1A-03-08  0   07/10/2019 11:30:00     Wednesday
EW1A-03-08  0   07/10/2019 12:00:00     Wednesday
EW1A-03-08  0   07/10/2019 12:30:00     Wednesday
EW1A-03-08  0   07/10/2019 13:00:00     Wednesday
EW1A-03-08  0   07/10/2019 13:30:00     Wednesday
EW1A-03-08  0   07/10/2019 14:00:00     Wednesday
EW1A-03-08  0   07/10/2019 14:30:00     Wednesday
EW1A-03-08  0   07/10/2019 15:00:00     Wednesday
EW1A-03-08  1   07/10/2019 15:30:00     Wednesday
EW1A-03-08  0   07/10/2019 16:00:00     Wednesday


You may need to massage this example and include additional columns in the PARTITION BY clause to ensure you're only selecting the correct near-duplicates but this should achieve the result you're after.

P.S. Its always a good idea in questions to include DDL (table definition), DML (INSERT statement with example data) and expected results to help clarify what you're trying to achieve.