Showing posts with label efficient. Show all posts
Showing posts with label efficient. Show all posts

Tuesday, March 20, 2012

Calling code outside of SQL

Hello again, hope this post is not offensive to the newsgroup.

I am just wondering what is an efficient method of invoking external code from SQL server. I do not want to load assemblies in SQL, I want to run something outside. So far options considered:

1. Windows Service - loop and check for a specified condition in database.
2. Web Service Listener - use SQL CLR to call the web service.
3. Queueing mechanism. Use MSMQ and widows service (similar 1) [probably reliant on CLR to send messages].
4. Service Broker - similar to 3. but message handling is SQL internal and in transaction.

All of the above are listeners in a way, could there be something that relies on event handlers - a stab in the dark.

Thank you for thoughts,

Lubomir

A lot depends on what you are trying to do. For option 1, consider using query notifications rather than looping and checking for a specific condition. Option 2 is often attractive unless invoking the external code is in the inner loop of an application. In that case, you might wish to consider rewriting the code so that instead of being external it is internal (using CLR inside the server). If this is a new application and not constrained by existing code, then open 4 seems more attractive than option 3 unless you need some feature specific to MSMQ. Look for information about External Activation in the Service Broker documentation. Other options you didn't mention would be using Biztalk Server or Indigo. You may find the discussion at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/BTS_2004WP/html/14bc36a8-69a9-48ed-8e4c-1c85202544c0.asp helpful.

sql

Thursday, February 16, 2012

Calculating Trends

Hello,
I am looking for the most efficient way to calculate a trend based upon
individual figures in a table. Here is an example (e.g. sold items):
Data:
date number
-- --
2001-01-01 3
2001-01-02 5
2001-01-03 10
expected result:
date totsl number of sold items
-- --
2001-01-01 3
2001-01-02 8
2001-01-03 18
Any idea hoe I can solve that with the best performance possible?
ThanksOn Thu, 2 Jun 2005 22:36:17 +0200, CrazyHorse wrote:

> Hello,
> I am looking for the most efficient way to calculate a trend based upon
> individual figures in a table. Here is an example (e.g. sold items):
> Data:
> date number
> -- --
> 2001-01-01 3
> 2001-01-02 5
> 2001-01-03 10
> expected result:
> date totsl number of sold items
> -- --
> 2001-01-01 3
> 2001-01-02 8
> 2001-01-03 18
> Any idea hoe I can solve that with the best performance possible?
> Thanks
"Calculating Running Totals"
http://www.sqlteam.com/item.asp?ItemID=3856
Summary: Depending on the size of your data, this is one instance where a
cursor may actually be worth using. This is because the cursor will only
make one pass through the table, while any set-based solution has to join
the table with itself - which can produce millions of temporary rows, at
least momentarily.
Most of the time, an even better idea is to let the SQL side just retrieve
the un-summarized data, and let the consuming application produce the
running total. In effect, this is moving the cursor from the database side
to the client side.|||Do:
SELECT dt, ( SELECT SUM( number )
FROM tbl t2
WHERE t2.dt <= t1.dt )
FROM tbl t1 ;
Anith|||Hello,
thanks for your help.
<CrazyHorse> wrote in message news:uvjo$K7ZFHA.2984@.TK2MSFTNGP15.phx.gbl...
> Hello,
> I am looking for the most efficient way to calculate a trend based upon
> individual figures in a table. Here is an example (e.g. sold items):
> Data:
> date number
> -- --
> 2001-01-01 3
> 2001-01-02 5
> 2001-01-03 10
> expected result:
> date totsl number of sold items
> -- --
> 2001-01-01 3
> 2001-01-02 8
> 2001-01-03 18
> Any idea hoe I can solve that with the best performance possible?
> Thanks
>