In NVARchar DataType column we can store both Single byte and Double byte data. Many a times we want to know how many records have Single byte or Double byte data. Let us understand this with an example.
--CREATE TABLE dbo.library
-- (libraryId int, username NVarchar(50))
--GO
--Populate Customer table with single byte and
--double byte CustomerName records
INSERT INTO dbo.library (libraryId, username)
VALUES (1, 'Anurag')
INSERT INTO dbo.library (libraryId, username)
VALUES (2, N'尊敬卿')
INSERT INTO dbo.library (libraryId, username)
VALUES (3, 'Siba')
GO
SELECT *
FROM dbo.library
WHERE username = CAST(username AS VARCHAR(50))
SELECT *
FROM dbo.library
WHERE username != CAST(username AS VARCHAR(50))
------------------------------------------------------------------------
Can we store double byte data type in varchar ?
Lets see
CREATE TABLE dbo.library1
(library1Id int, username Varchar(50))
GO
--Populate Customer table with single byte and
--double byte CustomerName records
INSERT INTO dbo.library1 (library1Id, username)
VALUES (1, 'Anurag')
INSERT INTO dbo.library1 (library1Id, username)
VALUES (2, N'尊敬卿')
INSERT INTO dbo.library1 (library1Id, username)
VALUES (3, 'Siba')
GO
SELECT *
FROM dbo.library1
--CREATE TABLE dbo.library
-- (libraryId int, username NVarchar(50))
--GO
--Populate Customer table with single byte and
--double byte CustomerName records
INSERT INTO dbo.library (libraryId, username)
VALUES (1, 'Anurag')
INSERT INTO dbo.library (libraryId, username)
VALUES (2, N'尊敬卿')
INSERT INTO dbo.library (libraryId, username)
VALUES (3, 'Siba')
GO
SELECT *
FROM dbo.library
WHERE username = CAST(username AS VARCHAR(50))
SELECT *
FROM dbo.library
WHERE username != CAST(username AS VARCHAR(50))
------------------------------------------------------------------------
Can we store double byte data type in varchar ?
Lets see
CREATE TABLE dbo.library1
(library1Id int, username Varchar(50))
GO
--Populate Customer table with single byte and
--double byte CustomerName records
INSERT INTO dbo.library1 (library1Id, username)
VALUES (1, 'Anurag')
INSERT INTO dbo.library1 (library1Id, username)
VALUES (2, N'尊敬卿')
INSERT INTO dbo.library1 (library1Id, username)
VALUES (3, 'Siba')
GO
SELECT *
FROM dbo.library1
No comments:
Post a Comment