1.declare t_hasSigned tinyint(3);
set t_hasSigned = 0;
set @sqlStr = concat('select count(playerId) from tb_sign where playerId =',iPlayerId , ' and day', iSignDate, '=1 into @t_hasSigned' );
prepare addSqlStr from @sqlStr;execute addSqlStr;
DEALLOCATE PREPARE addSqlStr;
SET tt_hasSigned = @t_hasSigned;
看这个例子,想把查询结果存到t_hasSigned中,但是系统报错,所以要存到@t_hasSIgned中,然后调用deallocate prepare 和 set 把值取出来。
2. set @sqlStr = concat('update tb_sign set day', iSignDate, '=', 1, ',lastSignDate=',concat('\'', year(now()), '-', month(now()), '-', iSignDate, '\''), ',accuSignCount=accuSignCount+1', ' where playerId = ' ,iPlayerId, ';');
这个例子中注意的是accuSignCount+1这个点,如果你把它当做已知变量,想用它的值就错了,所以要写到字符串里面,而不调用它的值。