Varchar and nvarchar are different. Careful Error

Source: Internet
Author: User
Today's call Program Always reports an error when executing SQL statements. The final result is varchar and nvarchar. Depressed.
This problem is not solved, but the character string passed by the API user is incorrectly encoded, leading to garbled characters. Create   Table   [ Test ] (
[ Nn ]   [ Varchar ] ( 50 ) Collate chinese_prc_ci_as Not   Null ,
Constraint   [ Pk_test ]   Primary   Key Clustered  
(
[ Nn ]
) On   [ Primary ]  
) On   [ Primary ]
Go

Select   *   From Test

Insert   Into Test (NN)
Values (N ' BSS? Why? § ID ' )

Insert   Into Test (NN)
Values (N ' BSS zookeeper» § ID ' )
/**/ /*
Server: Message 2627, Level 14, status 1, Row 1
The primary key constraint 'pk _ test' is violated '. Duplicate keys cannot be inserted in the object 'test.
The statement has been terminated.

*/

Declare   @ S   Nvarchar ( 50 )
, @ S2   Nvarchar ( 50 )

Select   @ S   = N ' BSS? Why? § ID ' , @ S2   = N ' BSS zookeeper» § ID '

Select   1   Where   @ S = @ S2

Select   1   Where N ' BSS? Why? § ID ' = N ' BSS zookeeper» § ID '
/**/ /*

(The number of affected rows is 0)


(The number of affected rows is 0)
*/

Declare   @ S   Varchar ( 50 )
, @ S2   Varchar ( 50 )

Select   @ S   = N ' BSS? Why? § ID ' , @ S2   = N ' BSS zookeeper» § ID '

Select   1   Where   @ S = @ S2

Select   1   Where N ' BSS? Why? § ID ' = N ' BSS zookeeper» § ID '
/**/ /*

(The number of affected rows is 1)


(The number of affected rows is 0)

*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.