Board index » delphi » SQL syntax questions

SQL syntax questions

I am using Borland Delphi 4 and have a couple of questions regarding
queries.  I have limited skill using SQL.  I would like to write a query
selecting each unique record for a particular customer using where
conditional statements.  Would the syntax be SELECT UNIQUE CUSTNO FROM
ORDERINFO WHERE ...  ?  If not, could someone help with the syntax?

Can I use the query results just as a table using a first and next
statement?
As an example can I use something similar to

While not Query1.EOF do  begin
...
Query1.next;

Thanks

 

Re:SQL syntax questions


You should avoid looping through records at the client, if you can achieve
the same task with a SQL statement (or a stored procedure if you are using a
database server).

With DBDEMOS (Paradox tables) :

select distinct orderno from items

--

Alain Quesnel

Product Manager
Argos Software
alainnos...@argosoftware.com

===========

Quote
"Brian Shigley" <Bshig...@in-touch.net> wrote in message

news:8h9icb$b2f3@bornews.borland.com...
Quote
> I am using Borland Delphi 4 and have a couple of questions regarding
> queries.  I have limited skill using SQL.  I would like to write a query
> selecting each unique record for a particular customer using where
> conditional statements.  Would the syntax be SELECT UNIQUE CUSTNO FROM
> ORDERINFO WHERE ...  ?  If not, could someone help with the syntax?

> Can I use the query results just as a table using a first and next
> statement?
> As an example can I use something similar to

> While not Query1.EOF do  begin
> ...
> Query1.next;

> Thanks

Re:SQL syntax questions


Quote
>Would the syntax be SELECT UNIQUE CUSTNO FROM
>ORDERINFO WHERE ...  ?  If not, could someone help with the syntax?

>Can I use the query results just as a table using a first and next
>statement?
>As an example can I use something similar to

>While not Query1.EOF do  begin
>...
>Query1.next;

If you run the query without the Where you will get a result set of all the
unique CustNo value in the table you are Querying.
You can iterate through that result set.  That will work well if this is a query
of a local table but will be slow with a client server backend.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:SQL syntax questions


Quote
Brian Shigley wrote in message <8h9icb$b...@bornews.borland.com>...
>I would like to write a query
>selecting each unique record for a particular customer using where
>conditional statements.  Would the syntax be SELECT UNIQUE CUSTNO
FROM
>ORDERINFO WHERE ...  ?  If not, could someone help with the syntax?

SELECT DISTINCT CUSTNO FROM
ORDERINFO WHERE ...

Quote
>Can I use the query results just as a table using a first and next
>statement?
>As an example can I use something similar to

>While not Query1.EOF do  begin
>...
>Query1.next;

Yes. This works fine.  Depending on what you need to do inside that
loop though, it's possible you might be able to do it through SQL
instead of using the loop - if so the SQL will do it faster (at least
if you are using an SQL server, it won't be so much difference if
you're using Paradox (e.g.) tables .

--
Wayne Niddery - WinWright Consulting
RADBooks - http://members.home.net/wniddery/
You have a Right to Free Speech, but not the right to make me listen,
nor to use my property as a soapbox.

Other Threads