Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 24th, 2006, 08:35 AM
Registered User
 
Join Date: Feb 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Insert Multiple Record in SQL Server in Once

Can anybody provide information regrading how to insert multiple record in once. I am currently doing assignment regarding Web warehouse management system asp.net . For example, when the book stock arrive. there are number of quantity stock there. When come to SQL Server, normally the SQL is perform single transaction. How can i get the SQL Statement can insert multiple record in once with different ISBN number only.

Let said: ProductID, Publisher, Date of publish, Are the same but only ISBN number is different. Instead of insert 1 by 1 is there any method can insert multiple times in once.

Thx in advance.



 
Old February 24th, 2006, 02:43 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Here's how. I don't know if it makes a lot of sense since somehow you'll have to get the ISBN numbers into the database one by one unless you can use DTS somehow from a file. Here's an example that works.

CREATE TABLE [ISBNNumbers] (
    [ISBNID] [int] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL ,
    [ProductID] [int] NULL ,
    [ISBN] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

With this data:

ISBNID,ProductID,ISBN
1,1,1234
2,1,1235
3,1,1236
4,1,1237

CREATE TABLE [tblProducts] (
    [ProductID] [int] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL ,
    [Publisher] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [TheDate] [datetime] NULL
) ON [PRIMARY]
GO


With this data:

ProductID,Publisher,TheDate
1,Johnny,2006-02-02 00:00:00.000

And a table called TheMaster:

CREATE TABLE [TheMaster] (
    [MasterID] [int] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL ,
    [ISBN] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [ProductID] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [Publisher] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [TheDate] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

TheMaster table is the target table. Now here's the query that will INSERT multiple rows.

INSERT into TheMaster (ISBN, ProductID, Publisher, TheDate)

(
SELECT ISBNNumbers.ISBN, Table2.ProductID, Table2.Publisher, Table2.TheDate
FROM ISBNNumbers INNER JOIN
                      Table2 ON ISBNNumbers.ProductID = Table2.ProductID
WHERE (Table2.ProductID = 1) )

Try it. It works. Still don't know if this is the best solution but it works.








Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert multiple row in server. Somesh .NET Framework 2.0 1 June 1st, 2007 08:03 AM
insert multiple record in sql server annie_stwg ASP.NET 2.0 Basics 4 September 19th, 2006 08:56 AM
Insert multiple records using one SQL Query. Deepak Chauhan SQL Language 3 April 12th, 2006 07:43 AM
errro trying to insert record to sql server method ASP.NET 1.0 and 1.1 Basics 1 May 20th, 2005 08:24 PM
Adding a new record to a sql server DB morpheus VB How-To 6 August 6th, 2003 06:15 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.