create proc FOOD_SALES_INIT @time_year char(10),@time_mont char(10)
as
update FOOD_SALES
set 
FOODS_SUM=(
select sum(GOODS_PRICE * KG) from FOOD_SALES  where TIME_YEAR=@time_year and TIME_MONT=@time_mont
)update FOOD_SALES
set 
PRICE_ACCU=(
select sum(FOOD_SUM) from FOOD_SALES   where TIME_MONT>'01' and TIME_MONT<@time_mont and 
TIME_YEAR=@time_year and TIME_MONT=@time_mont
)

解决方案 »

  1.   

    --如果将查询结果赋与字段,要将查询语句括起来create proc FOOD_SALES_INIT @time_year char(10),@time_mont char(10)
    asupdate FOOD_SALES
    set FOODS_SUM=(
    select GOODS_PRICE * KG from FOOD_SALES  where TIME_YEAR=@time_year and TIME_MONT=@time_mont)
    update FOOD_SALES
    set PRICE_ACCU= (select sum(FOOD_SUM) from FOOD_SALES   where TIME_MONT>'01' and TIME_MONT<@time_mont and 
    TIME_YEAR=@time_year and TIME_MONT=@time_mont)
    go
      

  2.   

    create proc FOOD_SALES_INIT @time_year char(10),@time_mont char(10)
    as
    update FOOD_SALES
    set 
    FOODS_SUM=
    GOODS_PRICE * KG from FOOD_SALES  where TIME_YEAR=@time_year and TIME_MONT=@time_mont
    update FOOD_SALES
    set 
    PRICE_ACCU=
    sum(FOOD_SUM) from FOOD_SALES   where TIME_MONT>'01' and TIME_MONT<@time_mont and 
    TIME_YEAR=@time_year and TIME_MONT=@time_mont
    这样也可以
      

  3.   

    set 字段名=(....)括号不能少
      

  4.   

    update t_table set f1 = 1 where .....
    update t_table set f1 = (select ff1 from t_t1) where ....