Special Character in SQL

后端 未结 5 923
礼貌的吻别
礼貌的吻别 2020-12-07 01:57

I have a problem with a special character inserted in a table of SQL Server 2008 R2. The point is that when i\'m trying to insert a string with the character º (e.g. 3 ELBO

5条回答
  •  粉色の甜心
    2020-12-07 02:12

    when I run this:

    print ascii('º')
    

    I get 186 as the ascii code value, so try:

    select * from YourTable Where Description like '%'+char(186)+'%'
    

    to see all the ascii codes run this:

    ;WITH AllNumbers AS
    (
        SELECT 1 AS Number
        UNION ALL
        SELECT Number+1
            FROM AllNumbers
            WHERE Number<255
    )
    SELECT Number,CHAR(Number) FROM AllNumbers
    OPTION (MAXRECURSION 255)
    

    EDIT op stated in a comment that they are using nvarchar columns.

    forger about ascii, use NCHAR (Transact-SQL) to output a degree symbol:

    print '32'+NCHAR(176)+'F' --to display it
    
    select * from YourTable 
        Where Description like '%'+NCHAR(176)+'%' --to select based on it
    

    and use UNICODE (Transact-SQL) to get the value:

    print UNICODE('°')
    

    returns:

    176
    

提交回复
热议问题