Arun
Arun

Reputation: 1704

how to convert numeric to nvarchar in sql command

I need to convert a numeric value to nvarchar in sql command.

Can anyone please help me.

Upvotes: 44

Views: 189247

Answers (4)

Spock
Spock

Reputation: 261

If the culture of the result doesn't matters or we're only talking of integer values, CONVERT or CAST will be fine.

However, if the result must match a specific culture, FORMAT might be the function to go:

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.

Of course, formatting the result should be a matter of the UI layer of the software.

Upvotes: 2

Anbuselvan
Anbuselvan

Reputation: 261

declare @MyNumber float 
set @MyNumber = 123.45 
select 'My number is ' + CAST(@MyNumber as nvarchar(max))

Upvotes: 6

Olivier S
Olivier S

Reputation: 921

select convert(nvarchar(255), 4343)

Should do the trick.

Upvotes: 49

Chris Fulstow
Chris Fulstow

Reputation: 41902

declare @MyNumber int
set @MyNumber = 123
select 'My number is ' + CAST(@MyNumber as nvarchar(20))

Upvotes: 18

Related Questions