Hi
In c# i have value computed like below . But i want at Sql column level. How it can be done. Sql column name is Attendance. If all records have present = false then Attendance column should have value 1.
C#
var result = objList.GroupBy(x => x.CalendarID)
.Count(g => g.All(x => x.Present == false));Thanks

Amit MohantyRank #112 · 20K reputationPosted Jun 23, 2023, 4:54 AM EDT
UPDATE YourTable SET Attendance = CASE WHEN ( SELECT COUNT(*) FROM YourTable AS sub WHERE sub.CalendarID = YourTable.CalendarID AND sub.Present = 0 ) = COUNT(*) THEN 1 ELSE 0 END;Deepak RawatRank #646 · 3.7K reputationPosted Jun 23, 2023, 5:51 AM EDT
UPDATE YourTable SET Attendance = CASE WHEN ( SELECT COUNT(*) FROM YourTable t WHERE t.CalendarID = YourTable.CalendarID AND t.Present = 0 ) = ( SELECT COUNT(*) FROM YourTable t2 WHERE t2.CalendarID = YourTable.CalendarID ) THEN 1 ELSE 0 END;