السلام عليكم ورحمة الله وبركاته
لدى جدول مخزن به اجمالى عددد ساعات العمل اليومية للموظف كالتالى وهناك حقل للتاريخ يسمى day_date
emplo_id total_hours
6:30 1
5:00 1
8:00 2
فكيف يمكننى الحوصل على مجموع عدد الساعات خلال الشهر لكل موظف ليكون الشكل النهائى كالتالى:
emplo_id Total_Hours
11:30 1
8:00 2
Select emplo_id, Format((Sum(total_hours)*1440)\60 ,'0') + ':' + Format((((Sum(total_hours)*1440)/60)-((Sum(total_hours)*1440)\60))*60,'0') As Total_Hours From tbl1 Group By emplo_id
VB6DAO كتب :Select emplo_id, Format((Sum(total_hours)*1440)\60 ,'0') + ':' + Format((((Sum(total_hours)*1440)/60)-((Sum(total_hours)*1440)\60))*60,'0') As Total_Hours From tbl1 Group By emplo_id
تم عمل الكود التالى ولكنه يعطى خطأ ؟
كود :
Select emplo_id, Format((Sum(all_day_hours) * 1440) / 60 ,'0') + ':' +
Format((((Sum(all_day_hours)*1440) / 60) - ((Sum(all_day_hours)*1440) / 60))*60,'0')
As Total_Hours From day_off Group By emplo_id
رسالة الخطأ
إقتباس :Msg 8117, Level 16, State 1, Line 1
Operand data type nvarchar is invalid for sum operator.
؟؟؟؟؟؟؟
...................................
.
انتبه فيه نوعين من علامات القسمة احداها / والأخرى \ وهي موجودة بشكل مقصود، لا تغيرها، انسخها كما هي
اذا كان الحقل all_day_hours هو nvarchar
كود :
Select emplo_id
, Format((Sum(CDate(all_day_hours)) * 1440) \ 60 ,'0') + ':' + Format((((Sum(CDate(all_day_hours))*1440) / 60) - ((Sum(CDate(all_day_hours))*1440) \ 60))*60,'0') As Total_Hours
From day_off
Group By emplo_id
اذا كان الحقل all_day_hours هو time
كود :
Select emplo_id
, Format((Sum(all_day_hours) * 1440) \ 60 ,'0') + ':' + Format((((Sum(all_day_hours)*1440) / 60) - ((Sum(all_day_hours)*1440) \ 60))*60,'0') As Total_Hours
From day_off
Group By emplo_id