Dynamic SQL versus building query on client

Dynamic SQL versus building query on client

Post by Keith Marbac » Fri, 21 Sep 2001 22:48:42



My client software is written in Delphi.

My Delphi program accepts user from which the dataset is selected.

Which is a better approach:

Approach 1:
Have Delphi contain logic to build the SQL select query, then pass the SQL
to the server for execution.

Approach 2:
Have Delphi call a SQL stored procedure, passing parameters that specify how
to build the query, then let the SQL sp build the query dynamically and
execute via exec.

I like the idea of Approach 2, but not if there is a big performance hit.

 
 
 

Dynamic SQL versus building query on client

Post by BP Margoli » Sat, 22 Sep 2001 08:46:48


Keith,

In the scenario presented, I'd go with the second approach, AND I'd use
sp_ExecuteSQL instead of EXEC. You have an increased probability of having
the query plan cached by using sp_ExecuteSQL.

You should have a performance improvement rather than a performance
degradation by following the second approach, but more importantly, IMHO,
the huge advantage of the second approach over the first is if you need to
change the SQL code in your application, you can change it in a single place
rather than having to hunt down every place where the Delphi application is
executing and trying to update the Delphi .exe's simultaneously.

-------------------------------------------
BP Margolin
Please reply only to the newsgroups.
When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc.) which
can be cut and pasted into Query Analyzer is appreciated.


Quote:> My client software is written in Delphi.

> My Delphi program accepts user from which the dataset is selected.

> Which is a better approach:

> Approach 1:
> Have Delphi contain logic to build the SQL select query, then pass the SQL
> to the server for execution.

> Approach 2:
> Have Delphi call a SQL stored procedure, passing parameters that specify
how
> to build the query, then let the SQL sp build the query dynamically and
> execute via exec.

> I like the idea of Approach 2, but not if there is a big performance hit.


 
 
 

Dynamic SQL versus building query on client

Post by Keith Marbac » Fri, 07 Dec 2001 23:27:09


I will try that later today. I was hoping to avoid any temp tables.

What I have is a list of customers in one table, and a list of phones in
another. Each cust has 0 or more phones. I'm building a list of customers
with their main phone number (where Seq is min for that customer). This list
is built whenever I need a lookup list for customers, so, I'm worried about
execution speed.


Quote:> My client software is written in Delphi.

> My Delphi program accepts user from which the dataset is selected.

> Which is a better approach:

> Approach 1:
> Have Delphi contain logic to build the SQL select query, then pass the SQL
> to the server for execution.

> Approach 2:
> Have Delphi call a SQL stored procedure, passing parameters that specify
how
> to build the query, then let the SQL sp build the query dynamically and
> execute via exec.

> I like the idea of Approach 2, but not if there is a big performance hit.

 
 
 

1. ODBC: Building dynamic queries

I'm using MS IIS 1.0 with ODBC 2.5 to connect to various databases,
including one MS SQL Server 6.5. I would like to allow queries from a html
page in which some fields could be left blank and thus should be excluded from
the query. For efficiency reasons I'd like to avoid defaulting the parameter
to "%" (or "%%" as is the syntax of IDC).

I have tried a "twostatement" sql approach in which I build up a where
clause text variable in the first statement and use this variable in the

my ODBC driver does not appear to accept this kind of syntax. It gives me

complete expressions as parameters to sql statements.

Does anyone know an approach to achieve exclusion of parameters from the where
clause of sql statements? Any comments on these observations?

Thanks for any help,

Tor Erlend F?gri, Siemens Nixdorf Informasjonssystemer AS

2. Pick Freeware FTP Site

3. Build a dynamic query in runtime - variable problem

4. Selecting from list boxes and combo

5. Coalesce: building dynamic query in stored procedure

6. SQL Query Search

7. Please Help, Cannot build dynamic query because of character limit

8. MS ACCESS to ORACLE via WABI on SOLARIS, Help!!!

9. dynamic query building

10. Build Dynamic Query

11. Please Help, Cannot build dynamic query because of character limit

12. Stored Procedures VERSUS Client-Side Queries

13. queries versus tcursors versus filters