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
257 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
[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
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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 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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

630 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