views:

30

answers:

2

Hello... Suppose we have a table with collumns (A,B,C) We want to search this table based on a criteria that is calculated from collumn C... and other parameters

Because the calculation is complex and cant be represented in sql query... what should i do? Make the filtering at application level ?

A: 

An alternative could be to create a function/stored procedure on the database that do the math for you and then call it in the where clause of your query

il_guru
+1  A: 

No silver bullet here.

Pros

You can have pretty complex calculations at the database level, the pros of doing it at database level are that the RDBMS is closer to the data and transporting data back and forth from disks, through RDBMS, through network, to application is usually more expensive then doing calculations in RDBMS (where SQL is executed) and shipping only results to the application.

Another pro is that centralizing the logic makes the system easier to maintain, but...

Cons

...depending on your database of choice, you might not have a wide choice of programming languages available in the RDBMS layer, so for more complex things it might get really awkward coding your task in some procedural SQL variant.

Other reasons for not doing it at the RDBMS level is if the calculations are resource intensive (cpu, memory; think O(n!) problems and such) and the size of the output is comparable to input. In this case shipping data to the application side might be interesting to relieve the database server resources (you are in a sense distributing the computing tasks; however if your application server lives on the same hardware as database server you might not gain anything, unless you can push it all the way to the clients; look at three tier and multi tier architecture).

Unreason
microsoft sql i am using... how can i use a programming language with sql server?
Parhs
@Parhs, you could start with http://www.aspfree.com/c/a/MS-SQL-Server/Implementing-Managed-code-in-SQL-Server-2005-using-Visual-Studio-NET-2005/
Unreason