hi all,
I would like to create a function which can eval string expressiion
select dbo.fn_eval_string('1+2+3')
return 6
and if I do dbo.fn_eval_string('2-(5-3)')
return 0
is that possible? it should also support multiply and division.Kevin,
One possible solution is to use dynamic sql, but you can not use it in a
udf. You will have to use a stored procedure instead.
Example:
create procedure p1
@.s varchar(50),
@.i int output
as
set nocount on
declare @.sql varchar(4000)
set @.sql = N'select @.i = ' + @.s
exec sp_executesql @.sql, N'@.i int output', @.i output
go
declare @.i int
exec p1 '2 * (3 + 5)', @.i output
print @.i
go
The code has not been tested.
Be careful with the use of dynamic sql, there are pros and cons that you
should be aware of, before using it.
http://www.sommarskog.se/dynamic_sql.html
AMB
"Kevin" wrote:
> hi all,
> I would like to create a function which can eval string expressiion
> select dbo.fn_eval_string('1+2+3')
> return 6
> and if I do dbo.fn_eval_string('2-(5-3)')
> return 0
> is that possible? it should also support multiply and division.
>
>
Showing posts with label eval. Show all posts
Showing posts with label eval. Show all posts
Monday, March 26, 2012
Friday, March 9, 2012
How to create a DTS package in SQL 2005?
How Do I create a package in SQL Server2005? I have the eval copy. I saw an icon for DTS in Management Studio but when right click there is no option for New.
SSIS is the way to go in SQL 2005. DTS is pretty much phased out in SQL 2005, and but is supported for backward compatibility. See topic "Upgrading or Migrating Data Transformation Services" for more information.
Subscribe to:
Posts (Atom)