Solved

General SQL-question!

Posted on 1997-08-18
2
173 Views
Last Modified: 2010-04-06
Hi!

I'm building a relational database (Paradox-tables) with about 15 tables that are related to eachother. When I delete a certain product that belongs to a certain customer I want to delete all records in about 10 tables with the following condition:

if (CustomerNumber = '???') AND (ProductNumber = '???') then
  delete the record


I've managed to use the TQuery object to delete the correct records from one table, the problem is how to do it from many tables, preferrably with one single SQL-question.
   The fields "CustomerNumber" and "ProductNumber" are of course present in all the tables.

   How do I solve this? Could you give me an example of what properties I need to set and the exact formulation of the SQL-query, I would be very grateful.

Daniel Persson, Sweden
0
Comment
Question by:Dippen
2 Comments
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
Don't know much about SQL, but I would just iterate through all the tables and fire that SQL-query on them.

But maybe this can help. OOPSOFT gives at this moment their SQL editor SQL Express away for free! It's the full version! Though you have to be quick because they offer this only for a limited time. Just look at their site and I hope you'll find your answer there.


0
 
LVL 1

Accepted Solution

by:
Zonnald earned 150 total points
Comment Utility
If the query is about the same for all tables why not use a string variable to name the table in the 'FROM' clause this way the same query can be used.

Alternatively you can pass the table name in hetrogenious query using the :TABLENAME notation.  Where TABLENAME CONTAINS the string for the table and the : means that this is a parameter assigned to the query component.  
Follow is the help out of DELPHI (3) which discusses the parameters and hetrogenious queries (not important that example is oracle)

Delphi supports heterogeneous queries, queries made against tables in more than one database. A heterogeneous query may join tables on different servers, and even different types of servers. For example, a heterogeneous query might involve a table in a Oracle database, a table in a Sybase database, and a local dBASE table. When you execute a heterogeneous query, the BDE parses and processes the query using Local SQL, so extended, server-specific SQL syntax is not supported.

To perform a heterogeneous query:

1.      Define a BDE standard alias that references a local directory, and set the DatabaseName property of the query component to that alias. To define BDE aliases use the Database Explorer.
2.      Define separate BDE aliases for each database accessed in the query.
3.      Specify the SQL statement to execute in the SQL property. Precede each table name in the SQL statement with the BDE alias for the database where that table can be found.
4.      Set any parameters for the query in the Params property.

5.      Call Prepare to prepare the query for execution prior to executing it for the first time.
6.      Call Open or ExecSQL depending on the type of query to execute.

For example, suppose you define an alias called Oracle1 for an Oracle database that has a CUSTOMER table, and Sybase1 for a Sybase database that has an ORDERS table. A simple query against these two tables would be:

SELECT CUSTOMER.CUSTNO, ORDERS.ORDERNO
FROM ":Oracle1:CUSTOMER", ":Sybase1:ORDERS"
WHERE CUSTNO = 1503
Contains the parameters for a query’s SQL statement.

property Params[Index: Word]TParams;

Description

Access Params at runtime to view and set parameter names, values, and data types dynamically (at design time use the Query Parameters editor to set parameter information). Params is a zero-based array of parameter records. Index specifies the array element to access.

Note

An easier way to set and retrieve parameter values when the name of each parameter is known is to call ParamByName. ParamByName cannot, however, be used to change a parameter’s data type or name.
Parameters used in SELECT statements cannot be NULL, but they can be NULL for UPDATE and INSERT statements.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now