Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 quadratic equation

Author  Topic 

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-02-10 : 09:52:19
Greetings!

Are there any samples out there for doing quadratic equations in
TSQL. Also is TSQL better for doing these equations or create them in
another programming language like c#, C++ and load them in as CLR. I heard you can do something like that. ANy leads will be much appreciated!

Merci

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-10 : 09:54:38
i think it would be much better to do this in clr procedures.
Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-02-10 : 09:57:18
ok visakh16...man do you get any sleep or are you doing this while sleep walking you are a workaholic! But of course we appreciate your help. I think you have this forum hooked up to your nervous system wirelessly or otherwise
ok, anywhere you can point me to read up on how to do this. I do not know C++ but I can dabble in c# .net stuff. I have all my values in SQL, the base values for the calculations.

THanks!!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-10 : 10:02:10
http://www.daniweb.com/code/snippet980.html
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-10 : 11:03:59
See here
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=77311



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2009-02-10 : 11:10:50
test
Umm - problem with this post so I'll do it in bits
It didn't like the second part of the cte being on the same line as the union all.

you need
minus b plus or minus the squared root of b squared minus 4ac all over 2 a
so

declare @a float, @b float, @c float
select @a = -2, @b = 7, @c = 15
;with d (d)
as
select d = exp(log(square(@b) - 4 * @a * @c)/2)
union all
select -d from d where d > 0
)
select (@b * -1 + d.d )/(2 * @a)
from d

decide what you want to do with the odd cases - like negative determinant, a=0 ....


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-10 : 11:30:46
Oh, this is for SOLVING quadratic equations?



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-02-10 : 11:38:41
yes..it was a simple question for solving quadratic equations .

Do it in SQL or C# CLR?

Thanks y'all

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2009-02-10 : 12:23:12
I would do it in t-sql (something like I posted above) - but then I always feel that writing a clr is an admission of failure.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

gingerninja
Starting Member

2 Posts

Posted - 2010-12-08 : 06:09:34
Hi,

Bit of a long shot this one, but I have stumbled on this forum post. I have a requirement to replicate some of the Excel Solver functionality within SQL. Ideally I wanted a purely TSQL function, but this looks unlikely now, so I'm also looking at CLR options.

What I need to do is analyse some financial fund data (36 price values) against somewhere between 2-5 benchmarks (also 36 price values each) and determine the sensitivities (weights) of the benchmarks that best follow the fund. In other words find a set of benchmark weights which minimizes the tracking error between the resulting benchmark and the fund. It's explained perfectly here: - http://www.andreassteiner.net/performanceanalysis/?External_Performance_Analysis:Style_Analysis

This is done with a few clicks in Excel, which is why it's so frustrating that I can't find a SQL Server contained solution. However, I do appreciate that it's a quadratic problem, so may not be so easily portable to SQL Server. I've have looked at the Frontline Solver (http://www.solver.com) and building a C# Dll, but I'd rather avoid that if possible.

Anyone got any thoughts or experience that might assist?

Many thanks,
Stephen
Go to Top of Page
   

- Advertisement -