Solved

Insert multiple  rows into a table in SQL Server 2000 using SQL

Posted on 2007-11-14
4
1,538 Views
Last Modified: 2010-08-05
I am trying to build a sql that can enter multiple rows into a table

Insert into dbo.mcsso_LBCityUserMapping (PortalUserID,LBCityUsername,Created,LastModified,LastModifiedBy)
Values (120855,'grulaa2',11/14/2007,11/14/2007,103884)
Values (120861,'korenovab1',11/14/2007,11/14/2007,103884)

Get teh error message.

Server: Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'Values'.
0
Comment
Question by:Sanjeet
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
cezarF earned 250 total points
ID: 20286231
try ...

Insert into dbo.mcsso_LBCityUserMapping (PortalUserID,LBCityUsername,Created,LastModified,LastModifiedBy)
(SELECT 120855,'grulaa2',11/14/2007,11/14/2007,103884
UNION
SELECT 120861,'korenovab1',11/14/2007,11/14/2007,103884)
0
 

Author Comment

by:Sanjeet
ID: 20286244
That worked, if I want to keep adding rows after the second one do I keep just adding a union clause?
0
 
LVL 14

Expert Comment

by:cezarF
ID: 20286248
yup
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20286265
in sql server 2008  this will also work

Insert into dbo.mcsso_LBCityUserMapping (PortalUserID,LBCityUsername,Created,LastModified,LastModifiedBy)
Values (120855,'grulaa2',11/14/2007,11/14/2007,103884) , (120861,'korenovab1',11/14/2007,11/14/2007,103884)
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

820 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