Inserting Superscript Numbers in MS SQL

Deadly 提交于 2020-01-03 16:43:13

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/13884018/inserting-superscript-numbers-in-ms-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!