August 16, 2009 at 12:13 am
I have a stored procedure in SQL which calculate formulas. The formulas are prepared in vb.net and are passed to my stored procedure. If formula contain ^ ,an error is raised.So how can I convert ^ to power function .I get the formula from users.
August 16, 2009 at 12:29 am
nahalsaeedi (8/16/2009)
I have a stored procedure in SQL which calculate formulas. The formulas are prepared in vb.net and are passed to my stored procedure. If formula contain ^ ,an error is raised.So how can I convert ^ to power function .I get the formula from users.
How is your program getting it's authorization into the database?
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
May 9, 2011 at 7:52 am
If you're sending a value like 2^3 that will not work. You'll have to use the Power function. Example below:
DECLARE @value int, @counter int;
SET @value = 2;
SET @counter = 1;
WHILE @counter < 5
BEGIN
SELECT POWER(@value, @counter)
SET NOCOUNT ON
SET @counter = @counter + 1
SET NOCOUNT OFF
END;
GO
The above script loops and does the following:
2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
Alternatively you can create a CLR function. Create a .Net class library with a function, compile it and register your function. You can then do something like this:
SELECT dbo.fn_SQLCLR(Formula) AS sig
May 10, 2011 at 8:45 am
This post is nearly 2 Years old !!! 😀
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply