Add values to a table based on values in another table

When a record is inserted or updated records in Table1 I want a record to be inserted into table3 for each record ID that is in table2 if the table2.id does not already exist in table3. What is the best way to do this? Could this be done with a trigger? If it could how would I write such a trigger. I have never written one before and this sounds like a hand full for my first effort. Your help will be greatly appreciated.

Thanks
0
Ruffone
3/23/2005 4:50:21 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

1 Replies
903 Views

Similar Articles

[PageSpeed] 18

You could do it in a trigger.  They're really not hard.  It's just SQL you want to run whenever a certain action happens on your table.  Pretty straightforward. Another option is to use stored procedures to do all of your inserts and updates.  Then, just code what could go in the trigger directly into your stored procedure.

Pete

0
PDraigh
3/28/2005 11:59:44 AM
Reply:

Similar Artilces:

Setting the value of a RadioButtonList based on a value in my sql table.
Hi folks, From a Sql database table I'm trying to display a RadioButtonList with two text values, "Buy" and "Sell". The actual numeric values in my table are 1 (Buy) or 2 (Sell). The name of the column in the table is "buy_sell". So how do I set the SELECTED="TRUE" property in the ListItem based on the value of my buy_sell column ? <asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1" OnInit="FormView1_Init"> .. .. <EditItemTemplate> <td><asp:RadioButtonList  DataSourceID="ObjectDataSource1" DataValueField="buy_sell" DataTextField...

Filtering Data For A Table With Given Values (Not Table Values From a Referenced Table)
I need to filter the records displayed for a table with a value provided in a textbox.  I am using a Dynamic Data Entities Website with Visual Basic Programming. Does anyone have a simple example to follow? Thanks for any advice. The only thing I know of without using the 4.0 Preview stuff is Josh Heyes project on codeplex Dynamic Data Filtering you can have a look at my tutorial on how to use it (c# I'm sorry) Dynamic Data Filtering – InstallationSteve Seeking the elegant solution.[Oh! If olny I colud tpye!]c# Bits blogOh, and don't forget to mark as ans...

Select values from one table based upon values in another...
How do I:Select f1, f2, f3, from tb1 where f1=Select f1 from tb2 where f1='condition'?Rex WinnCode-frog System Architects, Inc.VS 2005 Professional, C#, C++ Well... You might try reading up on some standard sql syntax... There are a number of different ways... Select t.f1,t.f2,t.f3 From tb1 t INNER JOIN tb2 t2 ON t.f1 = t2.f1 Where t2.f1 = 'condition'   Select t.f1,t.f2,t.f3 From tb1 t Where t.f1 IN (    Select t2.f1    From tb2 t2    where t2.f1 = 'condition')   Select t.f1,t.f2,t.f3 From tb1 t Where exists (select t2....

Getting a value from a SQL table displaying a specific page based on that value
May seem to newbie but here goes:I have a login page.  For the login I run a stored procedure with 4 return values, 0 - being valid, 1 - username exists already, 2 - username is incorrect3 - password is incorrectThis all works fine.  But from that I have the default page when the login credentials are correct.  The issue is I need to display a specific default page based on their location id from the member table which I already run a sp against for the login.  I have set up an .ascx page with a datagrid to display the results which works when I run the query for a h...

Copy values from one table to another table using LINQ to SQL?
Hello,I have two database tables that have different names but identical structure (columns).What is the easiest way to copy the values from one table to the other table using LINQ to SQL? Thanks,-- shawn shawn Hi, As far as I research, we could use "foreach"  to insert the data from one table to another table. The code is shown below.         //there exist two table list and listSecond        DataClassesDataContext dataClass = new DataClassesDataContext(); //create the instance of the DataCon...

Add additional entries to datagrid based on value from another table
I have a dropdownlist that is bound to a sql table named "courses" and contains the course name.  I have a datagrid that is bound to another table named "Units".  I display all units for the selected course in the datagrid.  However, the "Course" table contains a column No_Units, which is the amount of units that should be in the "Unit" table for the corresponding course, but the Unit table does not always contain all of the units.  I would like to automatically add the extra units to the "Unit" table so the...

Update table with value of another tables column?
How do I update a table's column, with the values of another tables column where the primary key between is Part_Number? table2 = temp_table  Update Actuator_Components Set Scanned_Drawings = table2.Scanned_Drawings   I tried this, and it completely executed, but it did nothing.   Declare @partNumber varchar(50), @scannedDrawing varchar(255) DECLARE temp_cursor CURSOR FOR SELECT Part_Number, Scanned_Drawing FROM temp_table OPEN temp_cursor FETCH NEXT FROM temp_cursorINTO @partNumber, @scannedDrawingWHILE @@FETCH_STATUS = 0BEGIN UPDATE Actuator_Components Set S...

Updating table with DropDownList values from another table
Hi. I'm trying to insert a value from DropDownList into database. I want to select value from DropDownList(DropDownList has SqLDataSource from another table) and insert that selected value into table.I'm trying to do this in DetailsView. And when I do, i get this error :  Must declare the scalar variable "@ServiceName"Problem starts when i try to edit a record. Oh, and the ServiceName in table Provided_Services is NULL. Please help me with this...Here is my code:  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID" &nb...

Extracting values from one table and query the values as a query for second table
Dear Perl DBI users I have two tables: currency_acc and amount_type. I would like to extract Names from the first table who have SGD currency and keep as a query for the second table Table 1 currency_acc +--------------------------------------- ID Name currency + +--------------------------------------- 23 RAM SGD 32 GOP GBP 45 RAN SGD 67 KRI USD 78 YUR SGD +------------------------------------ Table 2 amount_type +------------------------------------------------- ACC RAN KRI YUR RAM + +---------------------...

Select the value from a field of one table and place it into another table.
Using VB.NET, VS2005, SQL Server 2000. In a Windows Form, how could I provide a means for a user to select the value from a field of one table (a primary key value) and place it into another table (as a foreign key value)? The goal is to "assign" a person from one table to a location in another table by placing the person's primary key value into the location's foreign key field via an easy to use "selection" mechanism like a DataGridView or something.Thanks in advance for any help or examples.David  this is an ASP.Net forum - - you might want to check out: http://forums.microsof...

DropDownList bound to one table, selected value from another table
I posted this in another forum topic and I'm not getting any response.  I'm hoping maybe I will ge more help here since it pertains to a server control.  Hi I am having a very frustrating problem with a DropDownList.  The DropDownList is bound to one SQL Server 2005 table.  I do this progromatically with the following code:Public Sub EvaltrID() TryDim aType As String = txtAircraftType.SelectedValue Dim auth As String = Convert.ToInt32(MinLevel.Text) Dim active As String = "True"Dim iPilot As String = "True" Dim CrewPos As Strin...

Passing value from one control to another and inserting that value in a table
Hey all, sorry if the subject is confusing or has already been covered, but I have (obviously) a problem (at least one).This is using:Visual Studio 2005ASP.NET 2.0SQL Server 2005 ExpressVisual Basic I'm building a CRM system for my company and have run into a snag when attempting to add new customer records for a given client. The first thing that any CSR (or admin) must do upon accessing the CRM system is choose which client's customers they are actually working with (we have multiple clients and are ultimately responsible for providing customer service to the clients' end ...

DropDownList bound to one table, selected value from another table
Hi I am having a very frustrating problem with a DropDownList.  The DropDownList is bound to one SQL Server 2005 table.  I do this progromatically with the following code:Public Sub EvaltrID() TryDim aType As String = txtAircraftType.SelectedValue Dim auth As String = Convert.ToInt32(MinLevel.Text) Dim active As String = "True" Dim iPilot As String = "True"Dim CrewPos As String = txtCrewPos.SelectedValue Dim CrewPos1 As String = "SO" Dim instructSO As String = "True"Dim sesType As String = txtSessionType.Text Dim sesType1 As String ...

Insert multiple rows to table based on values from other 2 tables.
I have a form to assign JOB SITES to previously created PROJECT.  The  JOB SITES appear in the DataList as it varies based on customer. It can be 3 to 50 JOB SITES per PROJECT. I have "PROJECT" table with all necessary fields for project information and "JOBSITES" table for job sites. I also created a new table called "PROJECTSITES"  which has only 2 columns:  "ProjectId" and "SiteId". What I am trying to do is to insert multiple rows into that "PROJECTSITES" table based on which checkbox was checked.  The...

Web resources about - Add values to a table based on values in another table - asp.net.sql-datasource

A Muslim Immigration Ban and the Constitution
I continue to contend that the U.S. government establishing a religious test for immigration and entry would violate the Constitution. I find ...

Apple releases Lightning to SD Card Camera Reader for iPhone and iPad
My iPhone 6s Plus is a wonderful smartphone long battery life, great performance, and strong security. One of the biggest benefits, however, ...

One Twitter User Predicted the Name Saint West Months Ago!
The name Saint West quickly became a trending topic yesterday (December 7) when Kim Kardashian and Kanye West announced the name of their new ...

Chicago Releases Video of Police Using a Taser on Man Who Later Died
Chicago Releases Video of Police Using a Taser on Man Who Later Died

The most far-out 'Star Wars: The Force Awakens' collectibles every fan will want
Disney has some interesting new Star Wars toys for sale. Read more: http://on.mash.to/1TYHOBr Read more... More about Movies , Disney , Merchandise ...

Pixel C review: despite its great screen, battery life, and build quality, Android tablet software fails ...
Ron Amadeo / Ars Technica : Pixel C review: despite its great screen, battery life, and build quality, Android tablet software fails for a productivity ...

Officials ban half of Beijing's cars amid emergency smog alert
Filed under: Green , Emissions , China Cars will be banned based on their license plate number, as China's authorities desperately try to curb ...

NAACP Image Award Nominations Unveiled
The NAACP this morning announced nominees for its 47th annual Image Awards , which celebrate the accomplishments of people of color in TV, music, ...

The hopeful news about CO2 emissions and climate change
This story was originally published by Slate and is reproduced here as part of the Climate Desk collaboration. Our planet is heating up. The ...

Oscar Pistorius to Appeal to South Africa's Highest Court
BDlive Oscar Pistorius to Appeal to South Africa's Highest Court New York Times PRETORIA, South Africa — Oscar Pistorius will try to appeal ...

Resources last updated: 12/8/2015 7:24:15 PM