Re: Convert string to Number

From: Vishal Parkar (REMOVE_THIS_vgparkar_at_yahoo.co.in)
Date: 03/14/04


Date: Sun, 14 Mar 2004 13:00:59 +0530

hi ricky,
you will have to change the stored procedure on the basis of your table
structure.Let me explain you this stored procedure.

>>declare @t table (idd int, c1 varchar(40), results decimal(10,2))<<

above variable @t of type table will return the resultset which will hold
the value of
column idd=primary key/unique key value.
column c1=formula text
column results=output of formula

you can change this table structure on the basis of output that you require
from stored procedure.

>>while @x is not null
  begin
  select @x=min(idd) from formula
  where idd > @x<<

above loop will iterate through each and every row of the table "formula".
assuming idd as a primary key of the table. you will have to replace this
table name with yours, and the primary key/unique key column in the table.

>>select @c1 = c1 from formula where idd = @x<<

above select statement will pass the value of "formula string" that need to
be calculated, to the variable @c1, (replace this column name with the
"formula column" that you have).Also note that @x is the key value of each
row, that will be passed to this variable, each time loop iteration occurs.

>>set @str = 'select @y=' + @c1
exec sp_executesql @str, N'@y decimal(10,2) output' , @y output<<

above statement gets processed and output of formula is passed to the
variable @y, there shouldn't be any change here if correct value is passed
to the @c1 variable.

>>insert into @t values(@x, @c1, @y)<<

finally each row's fomula column and the calculation of the formula value
gets inserted into @t table.

--
Vishal Parkar
vgparkar@yahoo.co.in


Relevant Pages

  • Re: Looping through a Datagrid
    ... line basis? ... > What you can do is instead of attaching to the reader, ... > to an OleDbCommand representing your stored procedure. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Stored procedure to set defaults
    ... I dont know the basis of stored procedure.. ... hints.. ... > You should look up Typein the help file. ...
    (microsoft.public.fox.vfp.dbc)
  • Re: triggers
    ... > On what basis did you decide triggers are the best solution in this ... I would suggest using a stored procedure ...
    (microsoft.public.sqlserver.programming)