Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
takcw
Starting Member
3 Posts |
Posted - 2008-02-08 : 07:49:08
|
| Hi,I have a excel file that contains some contact information and includes the following columns:Date, Name, Address, Zip, City and phoneIn the db I have 2 tables that I need to insert into, the statment of the first table is:CREATE TABLE [TMsalg].[SQLUser].[tbl_Customer] ([CustomerID] int NOT NULL, [Name] varchar (50) NULL, [Adress] varchar (100) NULL, [ZipCode] varchar (50) NULL, [City] varchar (50) NULL, [Phone] varchar (50) NULL)and the other statment is:CREATE TABLE [TMsalg].[dbo].[Order_Ernering] ([OrderID] int NOT NULL, [Customer_id] int NULL, [Name] nvarchar (100) NULL, [Adress] varchar (100) NULL, [ZipCode] varchar (10) NULL, [City] varchar (100) NULL, [Phone] varchar (10) NULL, )Problems:-How do i insert into tbl_Customer table the custom only once from excel?-How do i insert into Contact_Company the correct customer_id and company_id?Thanks for the help |
|
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
Posted - 2008-02-08 : 07:58:44
|
| Just to clarify , do you mean "company_id" or "order_id"?Jack Vamvas--------------------Search IT jobs from multiple sources- http://www.ITjobfeed.com |
 |
|
|
takcw
Starting Member
3 Posts |
Posted - 2008-02-08 : 08:15:45
|
| I want first the excel file import to tbl_Customer table with CustomerID, and then import this to Order_Ernering table which have OrderID and correct CustomerID. |
 |
|
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
Posted - 2008-02-08 : 08:26:53
|
| I'm assuming the order id is coming from the Excel file , in that case, two options are:1)Wrapped in one transaction do the 2 INSERT statements2)INSERT into the first table and then have a TRIGGER to deal with the second table.You mention , you've got [Date, Name, Address, Zip, City and phone] in the Excel spreadsheet , therefore is your tbl_Customer.CustomerID a IDENTITY column? Jack Vamvas--------------------Search IT jobs from multiple sources- http://www.ITjobfeed.com |
 |
|
|
takcw
Starting Member
3 Posts |
Posted - 2008-02-08 : 08:41:37
|
| There is no order id or id from Excel file. The id from tbl_Customer and tbl_Order_Enering will provide self. |
 |
|
|
|
|
|
|
|