Mysql Procedure 使用concat申城动态字段、存储查询结果到临时变量
2013-06-24 18:38
369 查看
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这个点,如果你把它当做已知变量,想用它的值就错了,所以要写到字符串里面,而不调用它的值。
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这个点,如果你把它当做已知变量,想用它的值就错了,所以要写到字符串里面,而不调用它的值。
相关文章推荐
- 查询109号员工的员工号,员工名,工资,使用记录类型变量的字段接收查询结果
- [MSSQL]将查询结果赋值给变量时使用set与select的区别
- 使用SQLite数据库存储数据(3)-查询结果集
- 在存储过程中使用另一个存储过程返回的查询结果集
- sql server 存储过程中使用变量表,临时表的分析(续)
- mysql使用查询结果作为临时表
- SQLServer2008运用存储过程拆分字符串并查询结果并把结果存入临时表中。
- 将一个表的查询结果作为另一查询的字段(动态查询列)
- sql server 存储过程中使用变量表,临时表的分析(Z)
- Mysql 存储过程查询结果赋值到变量的方法
- oracle之存储过程5-查询结果保存到变量中去
- oracle的存储过程中使用变量或参数进行模糊查询(like的变量绑定)
- Mysql存储过程查询结果赋值到变量的方法
- Mysql 存储过程查询结果赋值到变量的方法
- MySQL使用查询结果生成临时表
- mysql存储过程将查询结果传给变量
- Mysql存储过程查询结果赋值到变量的方法
- Mysql 存储过程查询结果赋值到变量的方法
- HiveQL查询变量(动态参数值)的使用
- 临时表在存储过程中存放查询结果