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 2008 Forums
 Other SQL Server 2008 Topics
 Evaluate Math Expressions

Author  Topic 

Soumasree
Starting Member

1 Post

Posted - 2012-05-16 : 08:42:50
Hi,

I want a procedure or a function where I'll pass some parameters and get the result of expression (generated in the process). I will be saving the expression result in a seperate table to proceed with other activities.

I am unable to create a function because it doesn't allow the "EXEC" command.

I am unable to use stored procedure because I will be calling this from a select statement.

What shall I do ?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-16 : 20:57:01
why do you need EXEC command? also if you want to store it in a table then you should be doing this in procedure itself as UDF doesnt allow DML modifications.
Could you elaborate on what exactly you're trying to do and how you want it to be called from SELECT?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

godestalbin
Starting Member

2 Posts

Posted - 2012-05-21 : 23:47:07
I think I have exactly the same need:
I want to run a statement like:
select ItemID, dbo.CalculatedAttribute( ItemID, AttributeID )
from Item
The function will get formula and data from database to retrieve data (related to ItemId) and formula (related to AttributeID) for the specified ItemId and AtttributeId:
For instance formula could be Length x Width so it will build a string with data from database like '60 * 30' and should return the result.
Formula could be more elaborated.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-22 : 00:09:30
quote:
Originally posted by godestalbin

I think I have exactly the same need:
I want to run a statement like:
select ItemID, dbo.CalculatedAttribute( ItemID, AttributeID )
from Item
The function will get formula and data from database to retrieve data (related to ItemId) and formula (related to AttributeID) for the specified ItemId and AtttributeId:
For instance formula could be Length x Width so it will build a string with data from database like '60 * 30' and should return the result.
Formula could be more elaborated.


this is not a good way of implementing requirement. why are you storing formula as value itself? why not separate different attributes out into different column? what meaning does it have to keep different things under same column?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -