*sigh* perhaps you had too much to drink the night Ian and I went over
this with you =)
On SQL Server (and most other relational database servers) stored procs
will give you a perf increase because the server will have the execution
plan cached. SQL Server will do this as well for regular queries issued
against the DB, however, those caches are invalidated when you close the
connection (there is also the notion of "preparing" a query for use multiple
times, but once again, connection-specific, if you close the connection, or
retrieve it from a pool, the cache goes bye-bye).
I agree with you that there are ways you might want to filter the query.
In the case where you want to filter on the result set only, it is better to
place the code performing the select/logic in a function that returns a
table, and then select from the function, filtering the return values.
In the case where you need to place a filter on values that are not
exposed through the final result set (which is not easily predictable so
that you can't parameterize the function to provide those filters), then I
would agree that dynamic sql is the way to go.
Depending on how complex your logic is, portability of stored procs can
be very difficult or very easy. Typcially, I don't place much logic in my
database, and stick to the basics. It's not perfect, but it helps in
portability. An ORM is much easier to port, I'll give you that, but it's
very possible that it won't be a requirement.
--
- Nicholas Paldino [.NET/C# MVP]
-
mvp@spam.guard.caspershouse.com
P.S. Mojito...
"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1daceadcfdc26b0998c85c@msnews.microsoft.c om...[color=blue]
> Nicholas Paldino [.NET/C# MVP] <mvp@spam.guard.caspershouse.com> wrote:[color=green]
>> I am curious why you want to do something like this? You are better
>> off
>> creating stored procedures and then calling those from in your code.[/color]
>
> In my experience, that's only true in limited situations - such as
> where you know what kind of queries you need in advance. This often
> isn't the case, eg in a situation where the user can create their own
> queries from multiple criteria. In that situation, an ORM such as
> NHibernate (or DLINQ) is much better than writing the dynamic SQL
> yourself either in C# or in a stored proc.
>
> If you already know the form of the query though, what benefit is a
> stored proc over a parameterised query?
>
> (Just to mention: an ORM type solution is much better in portability
> terms, IME. Porting stored procs can be quite painful...)
>
> --
> Jon Skeet - <skeet@pobox.com>
>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too[/color]