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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
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.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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