Solved

How to insert mulitple values into 1 column using SQL Server 2005? I'm inserting a 10 character field with a leading space. I

Posted on 2013-01-30
4
248 Views
Last Modified: 2013-01-30
What is wrong with the following INSERT statement to store mulitple values into 1 column?

I get the error:

Msg 102, Level 15, State 1, Line 3
Incorrect syntax near ','.

INSERT INTO dbo.tblSpNY ( [Account Number] ) VALUES

(' 574336551'),
(' 232053211'),
(' 574253189'),
(' 574421706'),
(' 487016393'),
(' 574095968'),
(' 574343392'),
(' 574259296'),
(' 574352759'),
(' 574064021'),
(' 574336756'),
(' 574381195'),
(' 574486426'),
(' 539010882'),
(' 539065144'),
(' 238143319'),
(' 574346652'),
(' 574339429'),
(' 574345864'),
(' 574294131'),
(' 574393962'),
(' 574161212'),
(' 574345239'),
(' 594030965'),
(' 574356058'),
(' 684025866'),
(' 574336537'),
(' 574347652'),
(' 574024170'),
(' 574404837'),
(' 574339691'),
(' 618059530'),
(' 503038531'),
(' 601397524'),
(' 621098793'),
(' 323077247'),
(' 751018765'),
(' 723026026'),
(' 615091202'),
(' 601050814'),
(' 487156614'),
(' 622142642'),
(' 574117504'),
(' 574445841'),
(' 761117889'),
(' 574428506'),
(' 615061292'),
(' 539042484'),
(' 751018968'),
(' 509058813'),
(' 697015673'),
(' 574237484'),
(' 487020836'),
(' 422044616'),
(' 601086536'),
(' 622043211'),
(' 574159485'),
(' 697019939'),
(' 601365306'),
(' 539095426'),
(' 574098513'),
(' 480129498'),
(' 688028326'),
(' 476088339'),
(' 761066582'),
(' 618098049'),
(' 411015135'),
(' 761071331'),
(' 539039993'),
(' 323061996'),
(' 723053064'),
(' 601309314'),
(' 411040095'),
(' 756044021'),
(' 601384683'),
(' 621030542'),
(' 761071462'),
(' 601050237'),
(' 688027157'),
(' 476138888'),
(' 601307635'),
(' 539079445'),
(' 232012386'),
(' 761071334'),
(' 601302916'),
(' 621056845');
0
Comment
Question by:zimmer9
  • 2
  • 2
4 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 38837205
you are using the SQL 2008 syntax that wont work on sql2005, use this instead
INSERT INTO dbo.tblSpNY ( [Account Number] )
SELECT  ' 574336551'
union all
select '12123123'
0
 

Author Comment

by:zimmer9
ID: 38837284
This doesn't work either:
INSERT INTO dbo.tblSpNY ( [Account Number] )
SELECT ' 574336551',
union all
SELECT ' 232053211'

Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'union'.
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 38837322
Sorry

SELECT ' 574336551'   --- no need for the comma here
union all
SELECT ' 232053211'
0
 

Author Comment

by:zimmer9
ID: 38837323
I removed the comma. Now it works.

INSERT INTO dbo.tblSpNY ( [Account Number] )
SELECT ' 574336551'
union all
SELECT ' 232053211'
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

In this article I will describe the Copy Database Wizard 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.
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

19 Experts available now in Live!

Get 1:1 Help Now