1

I know strings need to be prefixed with N' in SQL Server (2012) INSERT statements to store them as UNICODE but do they have to be retrieved (SELECT statement) in a certain way as well so they are in UNICODE?

I am able to store international strings correctly with N notation but when I run SELECT query to fetch the records back, it comes as question marks. My query is very simple.

SELECT COLUMN1, COLUMN2 FROM TABLE1

I am looking at other possible reasons that may have caused this issue but at least I want to eliminate the SQL statement above. Should it read COLUMN1 and COLUMN2 columns correctly when they both store UNICODE strings using N notation? Do I have to do anything to the statement to tell it they are UNICODE?

2
  • it comes as question marks SQL Server Management Studio or your application? Check if it works with SSMS, if yes, then probably your app cannot read data correctly(driver,encoding,...) Commented May 3, 2016 at 17:08
  • @lad2025 My application Commented May 3, 2016 at 17:09

1 Answer 1

1

Within management studio you should not need to do anything special to display the correct values. Make sure that the columns in your table is defined as Unicode strings NVARCHAR instead of ANSI strings VARCHAR.

The following example demonstrates the concept:

    CREATE TABLE UnicodeExample
    (
         MyUnicodeColumn NVARCHAR(100)
        ,MYANSIColumn VARCHAR(100)
    )

    INSERT INTO UnicodeExample
    (
         MyUnicodeColumn
        ,MYANSIColumn
    )
    VALUES
    (
        N'איש'
        ,N'איש'
    )

    SELECT *
    FROM    UnicodeExample

    DROP TABLE UnicodeExample

In the above example the column MyUnicodeColumn is defined as an NVARCHAR(100) and MYANSIColumn is defined as a VARCHAR(100). The query will correctly return the result for MyUnicodeColumn but will return ??? for MYANSIColum.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.