日期:2014-05-17  浏览次数:20739 次

sqlserver2012 中文乱码怎么解决
在SQL server  management 里查的
select ISNULL(convert(nvarchar(20),datepart(year,tdate)),'未设定') as 年度,count(*)   from tb
     group by  datepart(year,tdate)

结果:
未?定 0
2013 0


怎么解决

------解决方案--------------------
中文前加大写N

select ISNULL(convert(nvarchar(20),datepart(year,tdate)),N'未设定') as 年度,count(*)   from tb
group by  datepart(year,tdate)


------解决方案--------------------
修改为这样试试:

select ISNULL(convert(nvarchar(20),datepart(year,tdate)),N'未设定') as 年度,
       count(*)
from tb
group by  datepart(year,tdate)


--或者这样,修改排序规则
select ISNULL(convert(nvarchar(20),datepart(year,tdate)),'未设定' collate Chinese_PRC_CI_AS) as 年度,
       count(*)
from tb
group by  datepart(year,tdate)