For SQL Server 2008, if I have a table with a field defined as either varchar(255) or nvarchar(MAX), can I input a comma in place of a value when using an insert statement if the field has no value?
For SQL Server 2008, if I have a table with a field defined as either varchar(255) or nvarchar(MAX), can I input a comma in place of a value when using an insert statement, if the field has no value? Allow Nulls is checked.
Microsoft SQL Server 2008
Last Comment
Zberteoc
8/22/2022 - Mon
lcohan
Sure you can. the difference between VARCHAR and NVARCHAR SQL types is that Nvarchar allows input/storage of UNICODE characters and Varchar doesnt.
OK, let's say I have a table with 14 fields that are defined as varchar(255) followed by the 15th field defined as bit, followed by 5 fields that are defined as varhar(255) followed by the 21st field defined as bit. How would you write an INSERT statement to load 1 record into this table using commas and a bit value of 1 for the 2 fields defined as bit.
For ex:
Insert Into dbo.tbl_CSL_Branches Values
(,,,,,,,,,,,,,,1,,,,,,1);
zimmer9
ASKER
When I use:
Insert Into dbo.tbl_CSL_Branches Values
(,,,,,,,,,,,,,,1,,,,,,1);
I get the error:
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ','.
It is Non-Unicode Variable Length character data type.
Example: DECLARE @varchar AS VARCHAR(100) = 'Pawan'
SELECT @varchar
NVarchar[(n)]
UNicode Variable Length character data type. It can store both non-Unicode and Unicode (i.e. Japanese, Korean, Chineese etc) characters.
DECLARE @Nvarchar AS NVARCHAR(100)= 'Pawan'
SELECT @Nvarchar
Complete code--
CREATE TABLE testComma( Id TINYINT NOT NULL Val1 VARCHAR(255) NOT NULL Val2 NVARCHAR(MAX) NOT NULL)GOINSERT INTO dbo.tbl_CSL_BranchesVALUES (1,',',',')GO--
http://www.sqlserver.info/database-design/varchar-vs-nvarchar/