0
我正在使用SQL Server 2005,我想檢查「TypeHopper_0x」的值if = 2,將「CycleHopper_0x」添加到@nat_weight
,這部分我能夠完成。現在@nat_weight = 1871
。聲明值的SQL Server劃分
現在我想將@nat_weight
和UPDATE
的值分配給「HPR_x_PRCT」,這是我遇到問題的地方,我將這個代碼作爲目標索引8000,會需要整個表運行。
對於料斗5的操作更新所述E1871分之177= 0.0149
DECLARE @nat_weight INT;
DECLARE @mattype1 INT;
DECLARE @mattype2 INT;
DECLARE @mattype3 INT;
-- get material type, need only hoppers 1-3, hopper 4,5,6 material type will never = 2
SET @mattype1 = (SELECT typehopper_01 FROM mm_Cycle_Data WHERE me38_cycle_data_ndx=8000);
SET @mattype2 = (SELECT typehopper_02 FROM mm_Cycle_Data WHERE me38_cycle_data_ndx=8000);
SET @mattype3 = (SELECT typehopper_03 FROM mm_Cycle_Data WHERE me38_cycle_data_ndx=8000);
-- if material type=2 then add to @nat_weight ,
IF @mattype1 = 2
set @nat_weight = (SELECT cyclehopper_01 FROM mm_Cycle_Data WHERE me38_cycle_data_ndx=8000);
IF @mattype2 = 2
set @nat_weight [email protected]_weight+ (SELECT cyclehopper_01 FROM mm_Cycle_Data WHERE me38_cycle_data_ndx=8000);
IF @mattype3 = 2
set @nat_weight [email protected]_weight+ (SELECT cyclehopper_03 FROM mm_Cycle_Data WHERE me38_cycle_data_ndx=8000)
UPDATE mm_Cycle_Data
Set HPR_1_PRCT =CycleHopper_01/@nat_weight, --my error might be here
HPR_2_PRCT =CycleHopper_02/@nat_weight,
HPR_3_PRCT =CycleHopper_03/@nat_weight,
HPR_4_PRCT =CycleHopper_04/@nat_weight,
HPR_5_PRCT =CycleHopper_05/@nat_weight
WHERE me38_cycle_data_ndx=8000
me38_cycle_data_ndx Cycle SettingHopper_01 SettingHopper_02 SettingHopper_03 SettingHopper_04 SettingHopper_05 SettingHopper_06 CycleHopper_01 CycleHopper_02 CycleHopper_03 CycleHopper_04 CycleHopper_05 CycleHopper_06 TotalHopper_01 TotalHopper_02 TotalHopper_03 TotalHopper_04 TotalHopper_05 TotalHopper_06 TypeHopper_01 TypeHopper_02 TypeHopper_03 TypeHopper_04 TypeHopper_05 TypeHopper_06 Get_Address t_stamp HPR_6_PRCT HPR_3_PRCT HPR_6_ErrPrct HPR_3_ErrPrct HPR_4_ErrPrct HPR_5_ErrPrct HPR_2_ErrPrct HPR_2_PRCT HPR_5_PRCT HPR_4_PRCT HPR_1_ErrPrct HPR_1_PRCT CurrentWorkingShift
------------------- ----------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- -------------- -------------- -------------- -------------- -------------- -------------- -------------- -------------- -------------- -------------- -------------- -------------- ------------- ------------- ------------- ------------- ------------- ------------- ----------- ----------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- -------------------
8000 61820 100 0 0 0 1.39999997615814 0 11871 0 0 0 177 0 274443072 2059773259 0 0 5744198 23988001 2 1 0 0 3 3 50 2015-10-06 15:16:37.267 0 0 0 0 0 -28.5714282989502 0 0 0 0 0 1 2
7999 939 100 10 1.5 0 0 0 21375 2181 334 0 0 0 7115425 388436 107363 0 0 0 2 1 3 0 3 0 38 2015-10-06 15:16:16.043 0 1.53800475597382 0 2.53365039825439 0 0 -4.2374324798584 9.84164714813232 0 0 0 100 2
7998 413 0 100 0 0 0 0 0 7962 0 0 0 0 0 3407112 0 0 0 0 1 2 3 0 0 0 39 2015-10-06 15:13:35.420 0 0 0 0 0 0 0 100 0 0 0 0 2
7997 61818 100 0 0 0 1.39999997615814 0 11836 0 0 0 175 0 274431201 2059773259 0 0 5744021 23988001 2 1 0 0 3 3 50 2015-10-06 15:13:03.387 0 1.51998627185822 0 0 0 -28.5714282989502 0 0 1 0 0 100 2
使用'1.0 * CycleHopper_01/@ nat_weight'來獲得浮點結果。 –
好故事。有問題嗎? – Hogan
我的目標字段「HPR_5_PRCT」應該是.0149,但它是0。 – Jad