应该是这样吧,varchar to nvarchar TRANSLATE(colName USING NCHAR_CS); nvarchar to varchar TRANSLATE(colName USING CHAR_CS);
当然了,转换时会有乱码的.这就是一开始就用nvarchar的原因呀.
以上朋友方法,怎么用。SQL提示没有TRANSLATE函数
以上朋友方法,怎么用。SQL提示没有TRANSLATE函数
以上朋友方法,怎么用。SQL提示没有TRANSLATE函数
那是因為你存儲到varchar時已經是亂碼了,建議用nvarchar如:繁體系統中,轉換簡體字的情況 select convert(nvarchar(10),'硬盘') /*結果:亂碼 硬? */select convert(nvarchar(10),N'硬盘') /*結果: 硬盘 */declare @a table (strMonth varchar(10), types varchar(10), [Money] int) insert @a select '1月','主板',10 union all select '1月','CPU', 20 union all select '3月','硬盘',49 union all select '4月','CPU', 11 union all select '5月','CPU', 12 union all select '6月','CPU', 8 union all select '3月','硬盘',4 union all select '1月','其它',37 union all select '3月','显示器',24 select * from @a godeclare @a table (strMonth nvarchar(10), types nvarchar(10), [Money] int) insert @a select '1月',N'主板',10 union all select '1月',N'CPU', 20 union all select '3月',N'硬盘',49 union all select '4月','CPU', 11 union all select '5月','CPU', 12 union all select '6月','CPU', 8 union all select '3月',N'硬盘',4 union all select '1月',N'其它',37 union all select '3月',N'显示器',24 select * from @a go /* 結果:---------- 硬?(1 個資料列受到影響) ---------- 硬盘(1 個資料列受到影響)(9 個資料列受到影響)strMonth types Money ---------- ---------- ----------- 1月 主板 10 1月 CPU 20 3月 硬? 49 4月 CPU 11 5月 CPU 12 6月 CPU 8 3月 硬? 4 1月 其它 37 3月 ?示器 24(9 個資料列受到影響) (9 個資料列受到影響) strMonth types Money ---------- ---------- ----------- 1月 主板 10 1月 CPU 20 3月 硬盘 49 4月 CPU 11 5月 CPU 12 6月 CPU 8 3月 硬盘 4 1月 其它 37 3月 显示器 24(9 個資料列受到影響)*/
定成nvarchar(),应该不会变吧.你再仔细查查
TRANSLATE(colName USING NCHAR_CS);
nvarchar to varchar
TRANSLATE(colName USING CHAR_CS);
select convert(nvarchar(10),'硬盘')
/*結果:亂碼
硬?
*/select convert(nvarchar(10),N'硬盘')
/*結果:
硬盘
*/declare @a table (strMonth varchar(10), types varchar(10), [Money] int)
insert @a select '1月','主板',10
union all select '1月','CPU', 20
union all select '3月','硬盘',49
union all select '4月','CPU', 11
union all select '5月','CPU', 12
union all select '6月','CPU', 8
union all select '3月','硬盘',4
union all select '1月','其它',37
union all select '3月','显示器',24 select * from @a
godeclare @a table (strMonth nvarchar(10), types nvarchar(10), [Money] int)
insert @a select '1月',N'主板',10
union all select '1月',N'CPU', 20
union all select '3月',N'硬盘',49
union all select '4月','CPU', 11
union all select '5月','CPU', 12
union all select '6月','CPU', 8
union all select '3月',N'硬盘',4
union all select '1月',N'其它',37
union all select '3月',N'显示器',24
select * from @a
go
/*
結果:----------
硬?(1 個資料列受到影響)
----------
硬盘(1 個資料列受到影響)(9 個資料列受到影響)strMonth types Money
---------- ---------- -----------
1月 主板 10
1月 CPU 20
3月 硬? 49
4月 CPU 11
5月 CPU 12
6月 CPU 8
3月 硬? 4
1月 其它 37
3月 ?示器 24(9 個資料列受到影響)
(9 個資料列受到影響)
strMonth types Money
---------- ---------- -----------
1月 主板 10
1月 CPU 20
3月 硬盘 49
4月 CPU 11
5月 CPU 12
6月 CPU 8
3月 硬盘 4
1月 其它 37
3月 显示器 24(9 個資料列受到影響)*/