Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Understanding functions.
Message
De
09/05/2007 15:41:37
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
09/05/2007 11:37:34
Mike Yearwood
Toronto, Ontario, Canada
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01223806
Message ID:
01223961
Vues:
22
>Hey all
>
>I've inherited a system with SQL stored procedures and functions. I want to clarify my understanding.
>
>Would this ...
>
>select @startdate = dbo.myfunction(@startdate)
>select @enddate = dbo.myfunction(@enddate)
>
>SELECT * from table where datefield between @startdate and @enddate
>
>be better than this...
>
>SELECT * from table where datefield between dbo.myfunction(@startdate) and dbo.myfunction(@enddate)

No. From BOL as is:

"User-defined Function Benefits
The benefits of using user-defined functions in SQL Server are:

They allow modular programming.

You can create the function once, store it in the database, and call it any number of times in your program. User-defined functions can be modified independently of the program source code.


They allow faster execution.

Similar to stored procedures, Transact-SQL user-defined functions reduce the compilation cost of Transact-SQL code by caching the plans and reusing them for repeated executions. This means the user-defined function does not need to be reparsed and reoptimized with each use resulting in much faster execution times.

CLR functions offer significant performance advantage over Transact-SQL functions for computational tasks, string manipulation, and business logic. Transact-SQL functions are better suited for data-access intensive logic.


They can reduce network traffic.

An operation that filters data based on some complex constraint that cannot be expressed in a single scalar expression can be expressed as a function. The function can then invoked in the WHERE clause to reduce the number or rows sent to the client. "

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform