SQL Server :: Insert Data From 2 Tables Into The 3rd Table?

Mar 18, 2011

I have 3 tables. I need to insert data from 2 tables into the 3rd table.

The first table has 2 fields -- c_id, c_key

The second table has -- t_id, u_id, partial_c_key

I need to insert c_id, u_id in the 3rd table.

Problem is partial_c_key in the second table contains only a part of the c_key in the first table.

Ex:

First table:

c_id--c_key
1--200A
2--200B
3--200C
4--301A

Second Table:

t_id -- u_id -- partial_c_key
1--23--200
2--36--301

In the data above partial_c_key 200 has 3 c_ids in the first table (1,2,3 with values 200A, 200B, 200C) and 301 has just 1 which is 301A.

In the 3rd table I need to insert c_id, u_id so the data should be

u_id -- c_id
23 -- 1
23 -- 2
23 -- 3
36 -- 4

How do I write a query to accomplish that?

View 4 Replies


Similar Messages:

SQL Server :: How To Insert One Table Data Into Another 2 Tables In Sql Server 2005

Feb 27, 2011

As I know, we can use INSERT INTO (....) SELECT FROM command to select data from one table and can insert into another table.

Now I need instead of 1 table, I want to select data from one table and Insert into another 2 tables.

Shall I write another INSERT INTO (..) SELECT FROM command or is there any other way?

View 7 Replies

SQL Server :: Selects Records From Some Tables And Insert Them In One Other Table?

Dec 14, 2010

I have a simple sql that selects records from some tables and insert them in one other table.This is what we need to do on a daily basis and we need to create a sql job for this.

View 3 Replies

SQL Server :: Script To Insert Records From One Table Into The Other Times Original Tables Count Field Value?

Jan 28, 2011

I have 2 table's

Table 1: Daily_item

Fields: Key_Guid Drescription Count

1 test 3

3 new item 2

I want to insert records form table 1 into table 2 but using the count field to duplicate the Key_guid record the new table.

New table example:

Table 2

Key_guid

1

1

1

3

3

View 5 Replies

Trigger In Sql Server - Insert Data In A Table It Gets Enter In Another Table?

Oct 8, 2010

im new to trigger concept

when i insert data in a table [DSR_OUT_PRO] data get enter in another table ie [trg_Insert_DSR_OUT_PRO] but 2 times..

Is it ok, or something is wrong..

View 1 Replies

DataSource Controls :: Insert Into A Table Based On Another Tables Numeric Operator Field

Nov 11, 2010

I have a insert into statement thats inserting my numbers from a numeric text box on my aspx page. I am choosing the Amount Type then putting in a a number.

So i have a drop down that i select example Direct Charge then i enter 600.00 and click add it puts that in to the databse for me woot..

I then put in say Misc Credit and enter 200.00 it inserts in that into the database woot.

The look up table that has my amount types has a field called numeric opperator which is either + or - the Credit being a - and the Charge being a + then my stored procedure takes all my + numbers and adds them up and subtracts all the - numbers.

I want to change that so that it actuall be inserted into the table as a - number form the start. So I want choose Misc Credit enter 200.00 and click add then my event says o yea thats a credit insert 200.00 as -200.00

How can I do that?

[code]...

View 1 Replies

SQL Server :: Get 3 Tables Sql Statement - Select Table C Column By Using Table A?

Mar 25, 2011

i have 3 tables which are Table A(a Id,b Id),

Table B(b Id,a Id,c Id),

Table C(c Id,b Id)

How can i select Table C column by using table A?

View 2 Replies

Insert A Join Statement - (Insert Data To Multiple Tables) - C#/SQL/T-SQL?

May 20, 2010

I have a Winform that has fields need to be filled by a user. All the fields doesn't belong to one table, the data will go to Customer table and CustomerPhone table, so i decided to do multiple inserts. I will insert appropriate data to CustomerPhone first then Insert the rest data to Customer table.

View 3 Replies

SQL Server :: Insert Data Into Table Got From Other Query?

Mar 25, 2011

I got data from different 2 tables and then this selected data trying to insert into new table. Selected data have multiple records.

how may i insert selected multirows into new table which has already been created into db.

Select fname, lname, Addresses.address from Persons Join Addresses on persons.ID = Addresses.PID

The result for this will be multi reocords then how can i insert into new table[already created]. within StoreProcedure

View 2 Replies

SQL Server :: How To Insert A Data Into Particular Table Using Dropdownbox Option

Jul 14, 2010

I want to insert some data into SQL Table.i'm using a form which contains one dropdownlistbox,four text boxes and one submit button.if i select a option in dropdownbox and entering somedata into the corresponding Textboxes and then clicking the submitbutton.it should inserted in to the correct table which one i have selected in the Dropdownbox option.

[Code]....

View 2 Replies

SQL Server :: How To Insert Values In Four Tables At A Time

Aug 13, 2010

How to insert values in four tables at a time......

These tables are having primary key and foreign keys...

View 3 Replies

SQL Server :: Insert Data Into Temp Table Will Occurs Wrong Order By Performance?

Jan 3, 2011

i just create table simply like this: create table tblDemo

(
PK_intID int primary key identify(1,1),
intHits int not null

[code]...

View 3 Replies

SQL Server :: Change Data Capture Records The Changes Like Insert, Update, And Delete To A Table?

Oct 26, 2010

CDC or Change data capture is a new feature in SQL Server 2008, which is an ability to record changes to table data into another table without writing triggers or some other mechanism, Change data capture records the changes like insert, update, and delete to a table in SQL server.I have sql 2005 and I have created triggers and tables CDC to capture the data. everything functions good and the data is being updated in the _CDC tables. all i need to do now is to generate the updated data as a report (excel/html)- what should I do ......?i need to show only the updated columns when user selects the date periods ( Range between dates ) and the person name - i need to display any updated info about that person during that period. So this updated columns about this person should be displayed in excel formatted column wise.

View 2 Replies

SQL Server :: Merging Three Tables Together In One Table?

Jan 7, 2011

I have three tables. I need to merge these three tables into one table. There is an ID column in all these three tables. The ID's can be same in all three tables or they can be different. If the IDs are same then I need to merge based on those ID's so if the ID 1 exists in Table A, table B and Table C then one row will be created in the resulting master tables, but if the Id's are different then one individual row will be created in each table.

Also, some of the columns are same in all three tables, but some are different, but if the ID is same then I just want to append that column in the existing table.

View 4 Replies

SQL Server :: Updating The Tables From Another Table?

Jan 12, 2011

I have two tables master and comp table. In master table, I have columns called LB1, LB2, LB1_ID, LB2_ID and in my comp table I have ID and CompName. I need to update my master table the following way

If LB1 in master table has a value of 'XYZ' then I need to find that value in Comp Table in column compName and then put the ID from comp table to master table in LB1

master

LB1 LB2 LB1_ID LB2_ID
XYZ HIJ
ABC KLM
DEF RAW
PQR VQS

Comp

ID CompName
1 XYZ
2 ABC
3 RAW
4 DEF
5 VQS
6 HIJ
7 KLM
8 PQR

I need to poulate my master table like this

master

LB1 LB2 LB1_ID LB2_ID
XYZ HIJ 1 6
ABC KLM 2 7
DEF RAW 4 3
PQR VQS 8 5

View 3 Replies

SQL Server :: Joins - Returns A Row When There Is Matching Table In Both Tables

Jan 29, 2011

Inner Join:- Returns a row when there is matching table in both tables. we can use comparison operator like =,<,>,<>

I created two tables

TableA


ID OID Type

1 1 A
2 6 B
3 7 C
4 10 D

TableB

ID Value
1 10
2 30
3 40
5 60
6 70

Basic Inner Join select Type From TableB as a inner join TableA as b on a.ID=b.OID Result Type

A
B

If i want only the type which has not match in tableB then i can use not in subquery i get the result if i m using select Type From TableB as a inner join TableA as b on a.ID<>b.OID then i get

Type
A
A
A
A
B
B
B
B
C
C
C
C
C
D
D
D
D
D

18 rows affetected i m suprise

View 3 Replies

SQL Server :: How To Export The Data From Dat File To Tables(Two Tables)

Dec 30, 2010

I am using bulk insert concept to export the data from dat file to tables(Two tables). I am using the temporary table for to do the calculation and insertion to two tables. My problem is whenever I selecting the temp table data after the execution of bulk insertion , the order is changing .I need to get the order as it is in file order(csv,dat,txt).

View 5 Replies

C# - How To Insert Data From Multiple Tables Into One

Jan 17, 2011

I am trying to insert data into a table using data from 2 other tables.

I need to use:

Project.ProjectID and Action.ActionID to be inserted into a table I have called

ActionDetails, WHERE the Project.ProjectID = 1
i've googled everywhere with no success :(

View 2 Replies

ADO.NET :: How To Insert Data In Both Tables Using TransactionScope

Sep 4, 2010

I am working on Sales application. In database i have SalesOrderHeader & SalesOrderDetail tables. They are almost typical Adventureworks db tables.

How to insert data in both tables using TransactionScope so if any of the record from the two tables generate error complete transaction roll-back.

One thing more I am using TableAdapters, My initial concept was inserting record in SalesOrderHeader, get SalesOrderId using Scope_Identity & bulkInsert Records to SalesOrderDetail using TransactionScope.

View 1 Replies

ADO.NET :: Insert Data Into Two Table At The Same Time - Multiple INSERT Statements?

Oct 26, 2010

I am trying to insert data into two table at the same time , but i'm successding in inserting data into only one table at a time on button click .

[Code]....

When i run the code, data gets inserted into table "implantDetails" only. Are multiple INSERT statments allowed?

View 1 Replies

SQL Server :: Database Design / Create A Separate Table Which Will Contain The Translations For All 50 Tables?

Sep 28, 2010

I am working on a multi-lingual application Assume the following:

Database has 50 tables and application has to support 5 languages

Which is the best way to design the database:

1. Include a langugae column for each table. Repeat the values for each language. Say i have a country table which has 100 countries in it. Then my design will contain 500 rows (100 for each langugae)

2. Create a separate table which will contain the translations for all the 50 tables in with a foreign key to the parent table.

Which is more efficient out of the above two.

View 3 Replies

Can Insert Rows To Table A Based On Values In Table B By A Single INSERT Statement

Dec 7, 2010

I am doing a data warehouse project.I have two tables tblA (id, type) and tblB(city, no_crimes, type).I want to create (insert) a number of rows based on the value of no_crimes.For Example, in tblB(Leeds, 2000, murder). SO, I need to insert 2000 rows into tblA by a single INSERT statement (not 2000 statements).

View 3 Replies

DataSource Controls :: Insert In To 2 Tables Using A SQL And Details View Insert Functionality?

Aug 12, 2010

I do have a details view, which insert data to a database table using SQL Datasource. Now i need the data to be inserted in to 2 tables instead of one.

View 1 Replies

Databases :: Best Way To Insert Data Into Multiple Tables?

Jan 22, 2010

I am using mysql as my database.From one of my web pages I want to insert data to 4 tables.All the data should be inserted to these different tables on a single button click from the web page.How can I achieve this?Which is most reliable way to insert data to multiple tables on a single click event?

Will the sql operation with 4 'insert' statements separated by semicolon work for me?

View 2 Replies

Access :: Insert Data Into Two Tables At The Same Time Using SQL?

Mar 14, 2011

I can probably figure out how to automatically insert data into two tables using ADO.net, and make one insert directly following the first automatically.

But can this be done using a single SQL statement? I've googled it and can't find much to help me out.

Note: I'm using MS Access as my database.

View 7 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved