开发者

Sum a column and update it to my table?

开发者 https://www.devze.com 2023-03-22 00:10 出处:网络
DECLARE@cnt int select @cnt = 2 the SUM works fine! SELECT SUM(Count) AS cnt FROM VF_CasINV_Cost where (K = \'K\') and (CalendarYear = 2010) AND (Item# < 99999992)
DECLARE  @cnt int
select @cnt = 2

the SUM works fine!

SELECT SUM(Count) AS cnt FROM VF_CasINV_Cost
where (K = 'K') and (CalendarYear = 2010) AND (Item# < 99999992)

But no data is updated to开发者_开发百科 the table, @cnt = 0 ?

UPDATE VF_CasINV_Cost
SET [Count] = @cnt
WHERE (K = 'K') and (CalendarYear = 2010) AND (Item# = 99999992)


@cnt and cnt are two different things. one's a server-side variable, one's a table field. Completely different storage areas in MySQL. If you want the query to update the VARIABLE, then you'd need to do

SELECT @cnt := SUM(Count) AS cnt 
...
0

精彩评论

暂无评论...
验证码 换一张
取 消