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
249 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Backup skipping a few tables 7 35
Update foreign key reference after insert 9 46
Need help debbuging stored procedure 21 32
Unable to save view in SSMS 21 53
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
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…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 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

22 Experts available now in Live!

Get 1:1 Help Now