Link to home
Start Free TrialLog in
Avatar of Gowtham Ramamoorthy
Gowtham Ramamoorthy

asked on

Need a query to replace strings with values without any ID num.....(Dont modify the data coz its the format i recieve)

Hi,

I need the values of price and weight to replaced in the expression 'price+weight' of formula1 table. COuld anyone help .

I have the below query tried but there is some error.

My query:
Select REPLACE('price+weight',INPUTNAME,INPUTVALUES) AS TIME FROM Formula1

--tABLE QUERY'S :
Create table FORMULA1
(
INPUTVALUES INT,
InputName VARCHAR(256),
)

Insert into Formula1
values(23,'weight')

Insert into Formula1
values(14,'PRICE')
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Could you give us an idea (based on the above input) what output you want from the query
I really think your Formula1 table is missing a field that indicates the entity to which the attribute-value pair belongs.  You appear to be aiming for an entity-attribute-value table layout.

As specified currently, this query will give you all the 'Price' and 'Weight' values summed:
Select sum(INPUTVALUES) as [TIME] from Formula1 where INPUTNAME in ('Price', 'Weight')

Open in new window

Avatar of Gowtham Ramamoorthy
Gowtham Ramamoorthy

ASKER

I want the values of price and weight to get replaced by the input values. Consider if it has the entity too like idnum 1 and 2
So, in your example, do you want your resultset to say literally
'23+14'
or
37
NO just 23+14 is fine. I dont need any dynamic query to do the math.
OK, the one that performed the sum was easier. I already gave you that one.  for the other version:

Select concat(
(select INPUTVALUES from Formula1 where INPUTNAME = 'Price'), '+',
(select INPUTVALUES from Formula1 where INPUTNAME = 'Weight'));

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Julian,

The table gets multiple input values and names and I need to replace the input values in the formula(Expression). to do the math.
What math do you need to do?

The original request concerned string concatenation?
You've already been given a query that adds them up.  It's the one using the SUM function.