当前位置:网站首页>About n before variables in SQL server and other usage analysis
About n before variables in SQL server and other usage analysis
2022-06-21 21:14:00 【Game programming】
Insert 、 Update data
When there is Chinese in the original data, insert it into SQL server Chinese garbled code will be generated in the database , The solution is :
The first step is to set the fields that need to store Chinese as nvarchar type
alter table Test_Info alter column name nvarchar(50)The second step is to add... Before inserting data N:
insert into Test_Info(name) values(N' cat ') Note that neither of the two is indispensable , Otherwise, it will lead to the appearance of Chinese garbled code !
Add N After that, it means that the string is a nvarchar type , Precede string with N You can convert a string to unicode code , Each string is stored in double bytes , In this way, the primary choice of Chinese characters will not be garbled
Inquire about
After completing the previous step, there will be no Chinese garbled code stored , However, when retrieving data, there will still be the phenomenon that Chinese cannot be retrieved . The solution is to add... Before a constant N
-- If not N Will not return correctly name Data for cats select * from Test_Info where name = N' cat 'The variable contains Chinese
More often, we need to query through variables , The variable contains Chinese , So how to SQL stored procedure 、 Add... Before variables of custom functions or scripts N Well ?
The following example uses a stored procedure
create proc test_proc(@name nvarchar(250), @enddateperiod date)asselect * from Test_Infowhere name=N''[email protected]+''and [date]<= @enddateperiodand [type]<>'Brand' There are two main parts that are different from the general stored procedure , First, when defining variables, they should be defined as nvarchar type , Two is through N’’+ Variable +’’ Add before the variables of the stored procedure N
Note that neither of the two is indispensable , Otherwise, the query will not produce correct results !
At the same time, you can :
create proc test_proc(@name nvarchar(250), @enddateperiod date)asDECLARE @SQL NVARCHAR(100)SET @SQL='select * from Test_Info where name=N'''[email protected]+''''EXEC (@SQL) But this method has multiple variables + Writing in the case of character constants is very cumbersome .
author : I left my life to work
Game programming , A game development favorite ~
If the picture is not displayed for a long time , Please use Chrome Kernel browser .
边栏推荐
- What is the gateway
- Cluster I -- LVS load balancing cluster NAT mode and LVS load balancing actual deployment
- volatile
- How functions are declared
- 11、 Beautify the interface
- LVS+Keepalived高可用群集实战部署
- Kubernetes-23: explain how to make CPU manager more flexible
- Simulate the input and get the contents of print output
- Idea has this class but can't find it
- Laravel imports and exports excel using phpoffice
猜你喜欢

What are the applications of 4.3-inch touch screen intelligent network central control host

Get the openharmony source code: get it from the deveco marketplace (1)

ASP. Net core creates razor page and uploads multiple files (buffer mode)

获取OpenHarmony源码:从DevEco Marketplace获取(1)

What is the C language callback function?

Book list given by Wu Jun to college students

Introduction to high performance intranet DNS system

向量與平面交點

Unity analog flashlight light source detector, AI attack range detection area, object detection in visual cone, fan-shaped area detection, circular area detection, cone area detection

向量与平面交点
随机推荐
Laravel imports and exports excel using phpoffice
It is said that the price of the iPhone 14 will rise; TikTok US user data is transferred to Oracle, and bytes cannot be accessed; Seatunnel 2.1.2 releases geek headlines
纵横网络靶场社区-Modbus协议
Cluster I - LVS Load Balancing Cluster Nat Mode and LVS Load Balancing Field Deployment
idea 有这个类但是找不到的问题
11、 Beautify the interface
STL之vector扩容机制
Vector expansion mechanism of STL
C语言回调函数到底是怎么回事?
What are some tricks that novice programmers don't know?
What are the applications of 4.3-inch touch screen intelligent network central control host
总结了嵌入式开发中几种常见的设备通信协议
What noteworthy technologies of gold: the importance of fund management
volatile
【CTF】攻防世界 MISC
随机森林(Random Forest)学习笔记
Decision tree learning notes
集群二---LVS负载均衡群集DR模式
产品创新 | 物极必反,回归真实生活的创新社交APP
Xcode插件管理工具Alcatraz