January 17, 2009 at 6:29 pm
rog pike (1/17/2009)
Jeff Moden (1/16/2009)
Heh... Come on folks. "We don need no stinkin' CLR!" 😛 This is a simple problem and it doesn't need a CLR.
The Gartner group commissioned a study and with Yale medical school they
found that the top five percent of sql experts were sqldatapaths:) Seriously,
it's 2009 and it shouldn't be necessary to rub two sticks together to get
a fire. There are valid reasons MS tries to quarantine it's sql experts and keep them away from developers (Linq is a type of immunization from sql type staph infections:). I find myself in agreement with this sentiment:
"State of the UNION", January 12, 2009
http://blog.databaseconsultinggroup.com/[/url]
It's time to feed your head some new ideas on how to program where your
sql expertise will serve you well. Learn to use Dataphor with sql server and you'll have the best of two worlds. And they won't collide:)
And there are folks like yourself that think you need a Lamborgini to haul manure. Now, except for accusing you of spamming this fine site, I've not called you any names like you've just done to me. I know it's nearly impossible for you to do so, but try being a gentleman for a change. Nah... never mind... I'm expecting too much...
--Jeff Moden
Change is inevitable... Change for the better is not.
January 20, 2009 at 9:04 am
Create table #t (ID int, Expression nvarchar(100), Expression2 nvarchar(200) null, Resultado real null)
insert into #t (ID, Expression)
select 1,'8*(1/2)-6' union all
select 2,'278*(1/4)-2' union all
select 3,'81*(3/5) +4'
update #t set Expression2 = 'update #t set Resultado = '+replace(Expression,'/','.0/')+' Where ID = '+convert(nvarchar(5),ID)
Declare @ID int, @Exp nvarchar(200)
Select @ID = min(ID) From #t
While @ID is not null
Begin
Select @Exp = Expression2 From #t Where ID = @ID
Exec (@Exp)
Select @ID = min(ID) From #t Where ID > @ID
End
Select * from #t
September 16, 2015 at 4:36 pm
If you want to evaluate more complex expression, the only easy way I know is with the SQL.NET product. It evaluates .NET expression directly in SQL stored procedure, function and trigger.
-- CREATE expression
DECLARE @sqlnet SQLNET = SQLNET::New('8*(1/2)-6')
-- EVALUATE expression
SELECT @sqlnet.Eval() -- (return: -6)quote]
Here is the product link:
https://github.com/zzzprojects/Eval-SQL.NET
You can also use the .NET Runtime Compiler if you want to evaluate in your own CLR procedure:
https://github.com/zzzprojects/Eval-Expression.NET
Let me know if it worked for you.
October 27, 2022 at 12:11 am
I found this discussion because I was looking for a way to get the default value for an int column. Here is what I came up with:
declare
@xStr nvarchar(40)
, @pStr nvarchar(40) = N'@dv int OUTPUT'
, @dv int
;
select @xStr = 'SELECT @dv = ' + definition from sys.default_constraints
where object_id = OBJECT_ID(N'dbo.MyIntColumnDefaultConstraint')
;
exec sp_executesql @xStr, @pStr
, @dv = @dv OUTPUT
;
select @dv [@dv], @xStr [@xStr]
;
Sincerely,
Daniel
Viewing 4 posts - 16 through 18 (of 18 total)
You must be logged in to reply to this topic. Login to reply