Solved

General SQL-question!

Posted on 1997-08-18
2
179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1341789
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
ID: 1341790
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 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