|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Find specific text in a stringHai ,
in a textbox am having text as "(20/100)+pay1*pay2" .it's a formula. and stored in a particular variable. string strformula="(20/100)+pay1*pay2" ; i've to substitute the value of the variable 'pay1' & 'pay2' and finding the value of that strformula. can any onr tell me how to find 'pay1' and 'pay2' in the variable strformula. it's urgent and reply immediately. Thanks in advance. Hi
I am not sure what this has to do with SQL Server! If the strings are unique then you could use the replace function. John <ksrajalaks***@gmail.com> wrote in message Show quote news:1139642884.262422.60580@g14g2000cwa.googlegroups.com... > Hai , > > in a textbox am having text as > "(20/100)+pay1*pay2" .it's a formula. and stored in a particular > variable. > string strformula="(20/100)+pay1*pay2" ; > > i've to substitute the value of the variable 'pay1' & 'pay2' and > finding the value of that strformula. > can any onr tell me how to find 'pay1' and 'pay2' in the variable > strformula. it's urgent and reply immediately. > Thanks in advance. > If am having the value as
string strvalue ="(12.23+233.56)*12/100"; i've to find the value.so that am converting to double. but it throws error. tel me how to find value? Hi
It is still not clear if you are using SQL Server! If you are then you can do something like: DECLARE @strformula nvarchar(60) DECLARE @nparams nvarchar(80) DECLARE @output decimal(10,4) DECLARE @pay1 decimal(10,4) DECLARE @pay2 decimal(10,4) SET @strformula = N'SELECT @output_val = (20.0/100)+(@pay_1*@pay_2)' SET @nparams = N'@output_val decimal(10,4) OUTPUT, @pay_1 decimal(10,4), @pay_2 decimal(10,4)' SET @pay1 = 233.56 SET @pay2 = 12.0/100 SELECT @strformula SELECT @nparams EXEC sp_executesql @strformula, @nparams, @output_val = @output OUTPUT, @pay_1 = @pay1, @pay_2 = @pay2 SELECT @output John <ksrajalaks***@gmail.com> wrote in message Show quote news:1139650655.809064.217710@f14g2000cwb.googlegroups.com... > If am having the value as > string strvalue ="(12.23+233.56)*12/100"; > i've to find the value.so that am converting to double. but it throws > error. tel me how to find value? > First, this clearly isn't SQL Syntax, but that notwithstanding, you can
evaluate a function like this, (as long as it fits SQL Syntax of course) declare @value decimal (10,8) declare @formula varchar(200), @query nvarchar(2000) set @formula = '(12.23+233.56)*12/100' set @query = 'select @value = (' + @formula + ')' EXEC sp_executesql @query, N'@Value decimal(10,8) output', @value output select @value I would strongly suggest against it, since this is really not SQL's strongpoint. This is one of the rare cases where I would probably suggest you storing the expression and the answer in two columns (using the middle tier layer to calculate the value, or this method could be used in a a singleton insert.) -- Show quote---------------------------------------------------------------------------- Louis Davidson - http://spaces.msn.com/members/drsql/ SQL Server MVP "Arguments are to be avoided: they are always vulgar and often convincing." (Oscar Wilde) <ksrajalaks***@gmail.com> wrote in message news:1139650655.809064.217710@f14g2000cwb.googlegroups.com... > If am having the value as > string strvalue ="(12.23+233.56)*12/100"; > i've to find the value.so that am converting to double. but it throws > error. tel me how to find value? > |
|||||||||||||||||||||||