question

sand143eep avatar image
sand143eep asked

Needed to Insert TM as superscript in a column

Hi,
Needed to insert a Column with Superscript for text values using the following i am able to insert numbers as superscript

insert into Testtable(Name,Date,)values('RACH²','2020-01-21 15:22:48.9100000')

but we are unable to superscript the text values, even after insert when we select the table then it is shown as questionmarks like RACH??

insert into Testtable(Name,Date,)values('RACHᵀᴹ','2020-01-21 15:22:48.9100000')

please suggest how i can insert a superscript text value.

sql-server-2008-r2
4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

What's the datatype for the "Name" field? is it varchar(x), or nvarchar(x)?

If it's shown as question marks on select, then try changing the font you're using to display the results.

0 Likes 0 ·

The datatype is nvarchar(20) , please suggest how i can change the font.

0 Likes 0 ·

Changing font will change the complete column i want RACH as big and TM only on the top

0 Likes 0 ·
insert into #Testtable(Name,Date)values(N'RACHᵀᴹ','2020-01-21 15:22:48.910')

Note the N at the beginning of the string for RACHᵀᴹ, this is to denote Unicode characters, if you don't put the N at the beginning, special characters are lost and converted to ?

I would however question the need to do such a thing, formatting like that should be done in the application layer, this is not what SQL is really built for, should have a separate column for the superscript text then get the application to superscript it, not SQL.

create table #testtable (name nvarchar(20), date datetime)
insert into #Testtable(Name,Date)values(N'RACH²','2020-01-21 15:22:48.910')
insert into #Testtable(Name,Date)values('RACHᵀᴹ','2020-01-21 15:22:48.910')
insert into #Testtable(Name,Date)values(N'RACHᵀᴹ','2020-01-21 15:22:48.910')
select * from #testtable<br>
0 Likes 0 ·

1 Answer

·
ThomasRushton avatar image
ThomasRushton answered

Hmm. Maybe it isn't a font problem...

Running this code on my local SQL server installation:

DECLARE @TestTable TABLE (name NVARCHAR(20));
INSERT INTO @TestTable (name) VALUES ('RACH²'), ('RACHᵀᴹ');
SELECT  * FROM  @TestTable;
WITH 
N1 AS (SELECT 1 AS N UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1),
N2 AS (SELECT 1 AS N FROM N1 a , N1 b),
N AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS N FROM N2)
SELECT name, n, ASCII(SUBSTRING(name,n,1))
FROM @TestTable, N
WHERE n <= len(name) ORDER BY name, n;

gives the last two characters (which should be the superscript TM) as ascii code 63 - which is the question mark.

So I'm guessing it may be a collation problem. I'll do some more digging.

Incidentally, there is the character code 153 - that's a *proper* TM symbol, ™, and the code works as expected.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.