Home All Groups Group Topic Archive Search About

Is there an eval() function in sql server 2000?

Author
11 Aug 2006 10:25 AM
Steve'o
SQL Server 2000 SP4

I would really like to allow users (admin only) to create custom
calcuilation columns by entering the calculation in a field as text eg

calc_1 varchar(100)
calc_1 = ((([col1]+[col2])/[col3])*100)

So the actual calculation is stored as plain text, then the views are simply
select blah, eval([calc_1]) from table.

eval() is a function in vb, but is there an equivalent built into sql server
2000?

Thanks.
Steve.

Author
11 Aug 2006 10:34 AM
ML
There is no such function in T-SQL. You'd have to resort to dynamic SQL. Read
more in this great article by Erland Sommarskog:

http://www.sommarskog.se/dynamic_sql.html

"If (adminOnly) { teach(admin, 'T-SQL') }"
- Julius Caesar, On Dynamic SQL, 87 BC


ML

---
http://milambda.blogspot.com/
Author
11 Aug 2006 12:11 PM
Steve'o
Many thanks ML, I did google a bit and could not find a relevant function but
thought I'd ask anyway in case I'd missed something.

Thanks for the link!

Steve.

Show quote
"ML" wrote:

> There is no such function in T-SQL. You'd have to resort to dynamic SQL. Read
> more in this great article by Erland Sommarskog:
>
> http://www.sommarskog.se/dynamic_sql.html
>
> "If (adminOnly) { teach(admin, 'T-SQL') }"
>  - Julius Caesar, On Dynamic SQL, 87 BC
>
>
> ML
>
> ---
> http://milambda.blogspot.com/
Author
11 Aug 2006 12:14 PM
ML
NP. Also be sure to read the rest of Erland's articles.
And remember this newsgroup. :)


ML

---
http://milambda.blogspot.com/
Author
11 Aug 2006 2:06 PM
Steve Kass
Steve,

You might be able to adapt this to your needs:
http://users.drew.edu/skass/sql/Infix.sql.txt

Steve Kass
Drew University
www.stevekass.com

Steve'o wrote:

Show quote
>SQL Server 2000 SP4
>
>I would really like to allow users (admin only) to create custom
>calcuilation columns by entering the calculation in a field as text eg
>
>calc_1 varchar(100)
>calc_1 = ((([col1]+[col2])/[col3])*100)
>
>So the actual calculation is stored as plain text, then the views are simply
>select blah, eval([calc_1]) from table.
>
>eval() is a function in vb, but is there an equivalent built into sql server
>2000?
>
>Thanks.
>Steve.

>
Author
12 Aug 2006 12:42 AM
Steve'o
Many thanks Steve, appreciate the code example (have _borrowed_ it for later
:) ).
Honestly, currently its beyond my brain power :)  So I think I'll just shove
the business logic in the middle tier and then charge the client when it
needs changing ;)
Just kidding.  But as the feature is a nicety and not a specified
deliverable, I'm going to leave it out,
Hopefully I'll get to a point where I can actually understand it :)

Thanks!
Steve.

Show quote
"Steve Kass" wrote:

> Steve,
>
> You might be able to adapt this to your needs:
> http://users.drew.edu/skass/sql/Infix.sql.txt
>
> Steve Kass
> Drew University
> www.stevekass.com
>
> Steve'o wrote:
>
> >SQL Server 2000 SP4
> >
> >I would really like to allow users (admin only) to create custom
> >calcuilation columns by entering the calculation in a field as text eg
> >
> >calc_1 varchar(100)
> >calc_1 = ((([col1]+[col2])/[col3])*100)
> >
> >So the actual calculation is stored as plain text, then the views are simply
> >select blah, eval([calc_1]) from table.
> >
> >eval() is a function in vb, but is there an equivalent built into sql server
> >2000?
> >
> >Thanks.
> >Steve.
> > 
> >
>

AddThis Social Bookmark Button