Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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?

Posted on 2016-09-20
6
Medium Priority
?
53 Views
Last Modified: 2016-09-21
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.
0
Comment
Question by:zimmer9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 40

Expert Comment

by:lcohan
ID: 41807641
Sure you can. the difference between VARCHAR and NVARCHAR SQL types is that Nvarchar allows  input/storage of UNICODE characters and Varchar doesnt.

http://www.sqlserver.info/database-design/varchar-vs-nvarchar/
0
 

Author Comment

by:zimmer9
ID: 41807708
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);
0
 

Author Comment

by:zimmer9
ID: 41807838
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 ','.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 30

Accepted Solution

by:
Pawan Kumar earned 2000 total points
ID: 41807847
Comma is field separator in the syntax thats why it is not working. Also we have supply comma in single quotes as it a string value

@Author -- Pls use below

--

INSERT INTO dbo.tbl_CSL_Branches VALUES
(',',',',',',1,',',',',',',',')

--

Open in new window

0
 
LVL 30

Expert Comment

by:Pawan Kumar
ID: 41807850
Varchar[(n)]
      
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
)
GO


INSERT INTO dbo.tbl_CSL_Branches
VALUES (1,',',',')

GO
--

Open in new window


--
Pls try and let us know in case of any issues..
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 41808710
Why not use this:
INSERT INTO YourTable (bit_col1, bit_col2) VALUES(1,1)

Open in new window

1

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question