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


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:

Create table FORMULA1
InputName VARCHAR(256),

Insert into Formula1

Insert into Formula1
Gowtham RamamoorthyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Could you give us an idea (based on the above input) what output you want from the query
Daniel WilsonCommented:
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

Gowtham RamamoorthyAuthor Commented:
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
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Daniel WilsonCommented:
So, in your example, do you want your resultset to say literally
Gowtham RamamoorthyAuthor Commented:
NO just 23+14 is fine. I dont need any dynamic query to do the math.
Daniel WilsonCommented:
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

Julian HansenCommented:
Or alternatively
FROM formula1 a,formula1 b WHERE a.InputName = 'PRICE' AND b.InputName = 'weight';

Open in new window

Neither of the provided solutions will give a meaningful result if there is more than one combination of PRICE / WEIGHT values in the table.
Will the table only have one combination of the PRICE / WEIGHT values?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gowtham RamamoorthyAuthor Commented:
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.
Julian HansenCommented:
What math do you need to do?

The original request concerned string concatenation?
Daniel WilsonCommented:
You've already been given a query that adds them up.  It's the one using the SUM function.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.