473,466 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Stored procedure - what to do...

sh
Hi.

I am quite new into stored procedures written in t-sql. (MSSQL server)

I have three different tables in my DB. Two of the tables (with different
data) are updated regularly and need to be joined into a third
table that works as the basis for an application in ASP.

The two former tables each contain a field with a persons identity number
(called PNR). I need to make sure that this number in a field the
first table is also contained in a field of the second table.

In case the number (10 digits) occurs in the fields of both tables, another
test is performed to check if the number occurs in the appropriate field in
table 3.

If it does nothing should happen to table 3 - however if the number is not
found in table 3 - then an insert of the number (and related data)
should be performed.

The operation needs to be done in a stored procedure since I have to check
about 15.000 rows in each query.

In ASP the operation can be done with multiple loops on the resultsets - how
can the same operation be accomplished in a stored procedure?

Sven
Jul 20 '05 #1
1 1893
Try this:-

INSERT INTO table3 (PNR,fld1,fld2)
SELECT table1.PNR,table1.fld1,table2.fld2
FROM table1
INNER JOIN table2 ON table1.PNR = table2.PNR
LEFT OUTER JOIN table3 on table1.PNR = table3.PNR
WHERE table3.PNR IS NULL

Not sure how efficient this is but is will work. I have assumed that
table3 will be a mixture of data between table1 and table2.

Regards

Garry

On Mon, 7 Jul 2003 13:55:27 +0200, "sh" <se**********@yahoo.com>
wrote:
Hi.

I am quite new into stored procedures written in t-sql. (MSSQL server)

I have three different tables in my DB. Two of the tables (with different
data) are updated regularly and need to be joined into a third
table that works as the basis for an application in ASP.

The two former tables each contain a field with a persons identity number
(called PNR). I need to make sure that this number in a field the
first table is also contained in a field of the second table.

In case the number (10 digits) occurs in the fields of both tables, another
test is performed to check if the number occurs in the appropriate field in
table 3.

If it does nothing should happen to table 3 - however if the number is not
found in table 3 - then an insert of the number (and related data)
should be performed.

The operation needs to be done in a stored procedure since I have to check
about 15.000 rows in each query.

In ASP the operation can be done with multiple loops on the resultsets - how
can the same operation be accomplished in a stored procedure?

Sven


Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
3
by: Rhino | last post by:
I've spent the last couple of hours trying to figure out how to debug a Java stored procedure and am just going in circles. The last straw came when I got "Cannot open input stream for default"...
4
by: Rhino | last post by:
Is it possible for a Java Stored Procedure in DB2 V7.2 (Windows) to pass a Throwable back to the calling program as an OUT parameter? If yes, what datatype should I use when registering the...
8
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
0
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how...
3
by: kd | last post by:
Hi All, How to debug a stored procedure? Thanks, kd
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
2
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.