0

I have a database with one table, let's say 'tablename'. Now, I want the first column of that table, named 'text' to be updated with the text it containts PLUS some new text which comes as result from another query executed over 'tablename2'. So, I want something like this:

UPDATE tablename SET text="current text" + (SELECT * FROM tablename2 where ID=12);

If 'text' value is 'Result not available' I want toappend ' here', so that the field value is 'Result not available here'

How is this possible? Thanks

Donal Fellows's user avatar
Donal Fellows
139k19 gold badges161 silver badges222 bronze badges
askedJul 18, 2012 at 20:31
1

2 Answers2

1

Try the concatenation operator (||):

UPDATE tablename SET text='current text'||(SELECT * FROM tablename2 where ID=12);

And I'm not sure, but you should use ' instead of " .

answeredJul 18, 2012 at 20:34
Andrei Micu's user avatar
Sign up to request clarification or add additional context in comments.

2 Comments

You're definitely correct about the quote character and the concatenation operator, but the rest of the SQL smelly fishy. (Not that that's your fault though.)
' only a single result allowed for a SELECT that is part of an expression'
1

I probably misunderstood your question, but let's try:

http://sqlfiddle.com/#!5/959e5/2

UPDATE Table1SET text = text ||     CASE      WHEN text = 'Result not available' THEN ' here'      ELSE (SELECT text FROM Table2 where id = 12)    END;
answeredJul 18, 2012 at 23:12
biziclop's user avatar

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.