Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting Superscript Numbers in MS SQL

Trying to insert a value into a varchar data field with the Superscript number of 4 (power of 4) at the end.

I'm able to insert/update values using superscript 2 and 3 (ie squared and cubed), but I can't get the power of 4 to enter correctly into a varchar field?

It does work if I switch the field to a nvarchar, but I'm trying to avoid that.

This works for squared or to the power of 2

update mytable
set myfield = 'test'+NCHAR(0xb2)

However, trying to get this to work using a 4 at the end...

update mytable
set myfield = 'test'+NCHAR(0x2074)

It just updates it a numeric 4 and not superscript 4. Is this because the VarChar datatype recognizes squared and cubed, but not any other ones?

like image 346
JeffB Avatar asked Oct 05 '22 16:10

JeffB


1 Answers

Superscripts beyond 3 are only available as Unicode characters, so you need to use an NVARCHAR instead of a VARCHAR for your data field, unfortunately.

Please see the ASCII table for allowable characters without using NVARCHAR - You'll only see superscripts for 2 and 3.

like image 104
Scott Chapman Avatar answered Oct 10 '22 02:10

Scott Chapman