我的表如下所示複雜的邏輯在SQL Server更新表
Regno Date Year Batch h1 h2 h3 h4 h5 Att
1138M0345 25-07-2013 3 1 P P P NULL NULL NULL
1138M0346 25-07-2013 3 1 P P P NULL NULL NULL
1138M0347 25-07-2013 3 1 P P P NULL NULL NULL
1138M0348 25-07-2013 3 1 P P P NULL NULL NULL
1138M0349 25-07-2013 3 1 P P P NULL NULL NULL
1138M0350 25-07-2013 3 1 P P P NULL NULL NULL
1138M0351 25-07-2013 3 1 P P P NULL NULL NULL
1138M0352 25-07-2013 3 1 P P P NULL NULL NULL
1138M0353 25-07-2013 3 1 P P P NULL NULL NULL
1138M0343 25-07-2013 3 1 A A A NULL NULL NULL
1138M0344 25-07-2013 3 1 A A A NULL NULL NULL
字段H1,H2,H3,H4,H5,和ATT可存儲空值 ATT場是存儲學生出勤的一天。我需要以下條件
下與 P/A/1/2更新場 ATT1. 'P' if H1 through H5 contains 'P' (Meaning present for the whole day)
2. '1' if H1 through H3 contains 'P' (Meaning present for the first session)
3. '2' if H4 and H5 contains 'P' (Meaning present for the second session)
4. NULL if any of H1 through H5 contains NULL (Meaning table needs to be updated completely)
5. Else 'A' (Meaning absent for the whole day)
誰能幫助我的邏輯
該字段**'app' **在哪裏? – Luv
使用CASE語句?你有什麼嘗試? –
對不起這個字段是Att –