开发者

Sum a column and update it to my table?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜