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.
Author |
Topic |
Lopaka
Starting Member
48 Posts |
Posted - 2008-06-26 : 12:23:27
|
I am trying to use execute to execute a string with a function. Unfortunately, there is no way to use Execute in a function. Does anybody now how to put the following into a function:DECLARE @String VARCHAR(1000)SET @String = '(50000 + ((25 - 7) * (0.17 * 50000) / (7)))'PRINT @StringEXECUTE ('SELECT ' + @String)Thank you...:)Robert R. Barnes |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-26 : 12:36:13
|
Why do you want to do this? there is no need of using dynamic sql here. Also you cant have dynamic sql inside a function. You need to make it a procedure if you want to use dynamic sql. |
 |
|
Lopaka
Starting Member
48 Posts |
Posted - 2008-06-26 : 12:51:47
|
some of the variables are actually coming in from other tables. the formula is user define in a field within another table. I wrote the example to make it easier to understand...:)Robert R. Barnes |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-26 : 13:06:30
|
quote: Originally posted by Lopaka some of the variables are actually coming in from other tables. the formula is user define in a field within another table. I wrote the example to make it easier to understand...:)Robert R. Barnes
can i ask what your original requirement is then? Lets see if it can done without use of dynamic sql. |
 |
|
Lopaka
Starting Member
48 Posts |
Posted - 2008-06-26 : 19:16:07
|
1. Function params pass in @stdcmp=50000, @medSvc=72. Table contains a field, (ColB), with the formula = '(@stdcmp+ ((ColA - @medSvc) * (0.17 * @stdcmp) / (@medSvc)))'3. It needs to run a select on other fields and return the sum of (ColB)Hope this helps...:)Robert R. Barnes |
 |
|
Lopaka
Starting Member
48 Posts |
Posted - 2008-06-26 : 19:17:03
|
3.a = (formula changes by data row, also the formula is set by engineers)Robert R. Barnes |
 |
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2008-06-27 : 11:17:13
|
No.You can't run dynamic SQL in a function.You will have to run it in a procedure and return the result as an output variable.e4 d5 xd5 Nf6 |
 |
|
|
|
|