Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
258 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 2000 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

722 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