VB前端,mysql 数据库。
select concat( month(frommonth),'月→',Cast(month(tomonth) AS CHAR),'月') as 征费时段 from mData 

select concat( month(frommonth),'月→',month(tomonth) ,'月') as 征费时段 from mData
frommonth 和 tomonth 都是 DATE 字段。
结果 12月→1(第二个实际是 12月)
     12月→6
请问如何解决这个问题?
谢谢。

解决方案 »

  1.   

    mysql 中根本不需要用cast .select concat( month(frommonth),'月→',month(tomonth) ,'月') as 征费时段 from mData应该就可以了。mysql> select concat( month(current_date()),'YY',month(current_date()) ,'YY');
    +-----------------------------------------------------------------+
    | concat( month(current_date()),'YY',month(current_date()) ,'YY') |
    +-----------------------------------------------------------------+
    | 12YY12YY                                                        |
    +-----------------------------------------------------------------+
    1 row in set (0.00 sec)mysql>
      

  2.   

    知道你的问题估计是什么了,你根本没有设置字符集! 在你的程序中先执行一下 "set names 'gkb'"mysql> select concat( month(current_date()),'月→',Cast(month(current_date()) AS
     CHAR),'月');
    +-------------------------------------------------------------------------------
    -+
    | concat( month(current_date()),'月→',Cast(month(current_date()) AS CHAR),'月')
     |
    +-------------------------------------------------------------------------------
    -+
    | 12月→12月
     |
    +-------------------------------------------------------------------------------
    -+
    1 row in set (0.00 sec)mysql> select concat( month(current_date()),'月→',month(current_date()) ,'月');+-------------------------------------------------------------------+
    | concat( month(current_date()),'月→',month(current_date()) ,'月') |
    +-------------------------------------------------------------------+
    | 12月→12月                                                        |
    +-------------------------------------------------------------------+
    1 row in set (0.00 sec)mysql>