DECLARE @cnt int
select @cnt = 2
SUM工作正常!
SELECT SUM(Count) AS cnt FROM VF_CasINV_Cost
where (K = 'K') and (CalendarYear = 2010) AND (Item# < 99999992)
但没有数据更新到表,@ cnt = 0?
UPDATE VF_CasINV_Cost
SET [Count] = @cnt
WHERE (K = 'K') and (CalendarYear = 2010) AND (Item# = 99999992)
答案 0 :(得分:1)
@cnt
和cnt
是两回事。一个是服务器端变量,一个是表字段。 MySQL中完全不同的存储区域。如果您希望查询更新VARIABLE,那么您需要执行
SELECT @cnt := SUM(Count) AS cnt
...