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
...
精彩评论