473,320 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Procedure for deleting records

Hi

I have created two tables 'TrainsMaster' & 'TransArrvlDepinfo'

Columns which I have created in 'TrainsMaster' are 'trainName,TrainNo, StartStaionId, & EndstationId'

Columns which I have created in ''TransArrvlDepinfo' are 'Stationcode, TrainNo, Arrvaltime,Depttime'

I have to delete few trains from 'TrainsMaster' for which the Startstationid or Endstationid are nulls which comes to 50 records

The above said null valued trains should be removed form ''TransArrvlDepinfo' table as well.

For example I have the following trains to be deleted from 'TrainsMaster'

Train Name Train No Startstionid endstationid
Yeshvantpur - Guwahati Express 201 NULL GHY
Jammutawi AC Special 905 NULL JAT
Amritsar AC Special 951 NULL ASR
Delhi - Howrah Special 232 NULL HWH

When I check the above trains in 'TransArrvlDepinfo' table there are lot of trains which passes through the staioncode 'ghy'

For example 'GHY' is the station code in which lots of trains run through. I need a procedure for deleting the above said trains with the same station code. i.e. I should be deleting only train no 201 for which the station code is 'ghy' similarly the above said trains should be deleted from 'TransArrvlDepinfo' table with their corresponding stationcodes.

Please give the procedure for deleting multiple records
Sep 17 '08 #1
2 2092
deepuv04
227 Expert 100+
Hi,
First you need to delete records from table TransArrvlDepinfo, and then delete from table TrainsMaster

use the following code:
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE DeleteTrainInfo
  2. AS
  3. BEGIN
  4.     -- Delete records from  TransArrvlDepinfo
  5.     DELETE FROM TransArrvlDepinfo
  6.     FROM TransArrvlDepinfo INNER JOIN
  7.          TrainsMaster ON TrainsMaster.TrainNo = TransArrvlDepinfo.TrainNo
  8.     WHERE (TrainsMaster.Startstationid IS NULL OR TrainsMaster.Endstationid IS NULL)
  9.  
  10.     -- Delete records from TrainsMaster
  11.     DELETE FROM TrainsMaster
  12.     FROM TrainsMaster
  13.     WHERE (TrainsMaster.Startstationid IS NULL OR TrainsMaster.Endstationid IS NULL)
  14. END
  15.  
To delete a specific train info pass train no as parameter and use it in where clause.
Thanks
Sep 17 '08 #2
Hi Thanks for your help.

Hi,
First you need to delete records from table TransArrvlDepinfo, and then delete from table TrainsMaster

use the following code:
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE DeleteTrainInfo
  2. AS
  3. BEGIN
  4.     -- Delete records from  TransArrvlDepinfo
  5.     DELETE FROM TransArrvlDepinfo
  6.     FROM TransArrvlDepinfo INNER JOIN
  7.          TrainsMaster ON TrainsMaster.TrainNo = TransArrvlDepinfo.TrainNo
  8.     WHERE (TrainsMaster.Startstationid IS NULL OR TrainsMaster.Endstationid IS NULL)
  9.  
  10.     -- Delete records from TrainsMaster
  11.     DELETE FROM TrainsMaster
  12.     FROM TrainsMaster
  13.     WHERE (TrainsMaster.Startstationid IS NULL OR TrainsMaster.Endstationid IS NULL)
  14. END
  15.  
To delete a specific train info pass train no as parameter and use it in where clause.
Thanks
Sep 17 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Subodh | last post by:
HI, I need to run same kind of transactions (basically deleting records) in a loop but I have only 1 hour in a day to run my procedure. So I need to set a timer in a SP so that SP terminates...
4
by: deprins | last post by:
Hello, I have wrote a stored procedure but its real slow. Its activated by a button on web page but its takes to long to process and the web server gives a timeout message after 5 minutes. Is...
1
by: Mark | last post by:
This question refers to a main form with a continuous form subform. After an error occurs after entering several records in the subform, how can I delete all the data in the main form and all the...
1
by: KC | last post by:
Hello, I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB. I have tweaked this DB to work for our small co. It has worked pretty well up until I made the mistake of deleting...
5
by: Mojtaba Faridzad | last post by:
Hi, with SetDataBinding( ) a DataGrid shows a DataView. user can select some rows in the grid by holding cotrol key. when user clicks on Delete button, I should delete all selected rows. I am...
0
by: jobs | last post by:
I have a gridview that I use to both select a record to be edited in a formview and to also delete records with. Because the selectcommand is grouping rows, my deletes stored procedure requires a...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
2
by: Deepamathi | last post by:
Thanks in advance for your help. I need a Stored Procedure that will do the following steps: 1. delete a single record from table GROUP 2. delete all records from table SUBGROUP with a matching...
3
by: gaurim | last post by:
I am facing the coding proble in the following Stored Procedure wherein I am trying to create a table after deleting it. and then I am trying to insert records from two other tables based on certain...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.