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
36 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
6 Comments
 
LVL 39

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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 28

Accepted Solution

by:
Pawan Kumar earned 500 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 28

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 26

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now