[英]how to convert numeric to nvarchar in sql command
I need to convert a numeric value to nvarchar in sql command. 我需要在sql命令中将数值转换为nvarchar。
Can anyone please help me. 谁能帮帮我吗。
select convert(nvarchar(255), 4343)
应该做到的。
declare @MyNumber int
set @MyNumber = 123
select 'My number is ' + CAST(@MyNumber as nvarchar(20))
declare @MyNumber float
set @MyNumber = 123.45
select 'My number is ' + CAST(@MyNumber as nvarchar(max))
If the culture of the result doesn't matters or we're only talking of integer values, CONVERT
or CAST
will be fine. 如果结果的文化无关紧要,或者我们只在谈论整数值,那么
CONVERT
或CAST
就可以了。
However, if the result must match a specific culture, FORMAT
might be the function to go: 但是,如果结果必须符合特定区域性,则可以使用
FORMAT
函数:
DECLARE @value DECIMAL(19,4) = 1505.5698
SELECT CONVERT(NVARCHAR, @value) --> 1505.5698
SELECT FORMAT(@value, 'N2', 'en-us') --> 1,505.57
SELECT FORMAT(@value, 'N2', 'de-de') --> 1.505,57
For more information on FORMAT
see here . 有关
FORMAT
更多信息,请参见此处 。
Of course, formatting the result should be a matter of the UI layer of the software. 当然,格式化结果应该与软件的UI层有关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.