SQL: Whats the difference between ... WHERE O.type = N'U' ... and ... WHERE O.type = 'U'
Today I came across an SQL statement that contains an element I've never seen. Maybe someone can elaborate? This SQL is from a stored procedure in Sybase ASE 15
SELECT O.id, OWNER = U.name, O.name, O.type FROM xxx.dbo.sysobjects O LEF开发者_如何学编程T JOIN xxx.dbo.sysusers U ON O.uid = U.uid WHERE (O.type = N'U' OR O.type = N'S' OR O.type = N'V') ORDER BY O.name
Running
SELECT O.id, OWNER = U.name, O.name, O.type FROM xxx.dbo.sysobjects O LEFT JOIN xxx.dbo.sysusers U ON O.uid = U.uid WHERE (O.type = 'U' OR O.type = 'S' OR O.type = 'V') ORDER BY O.name
gives the same result as the SQL above.
What does the N infront of the parameter do?
The N ensures the value stated is treated as unicode
It's a "nationalized" (Unicode) string.
The N stands for National - the N converts the VARCHAR to a NVARCHAR, which is used to store unicode data, which is used to store multilingual data in your database tables.
精彩评论