Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, everyone. I need a help for Query SQL. I have a table which Call Test has a

ID: 3848603 • Letter: H

Question

Hi, everyone.

I need a help for Query SQL.

I have a table which Call Test has a columns Id, Name, Reasons, and ReasonsDescription.

in column Reasons, I have a value like 1 or data value like 1|2 or like 1|2|3 and... Each number value in column Reasons Declared a string like 1 = "Hello",  2="World", 3=" SQL" and ... So, I need SQL Query to update a column ReasonsDescription, by checking values of column Reasons.

for example, if column Reasons has a value 1 then column ReasonsDescription update to Hello, or

if Column Reasons has a value like 1|2 then column ReasonsDescription update to Hello|World.

is anybody can help me please?

best regards.

Explanation / Answer

Consider We need to create following table TEST with values and update it as per your instructions:

after Executing UPDATE it should look like

Now Here is Complete List of queries that we need:

1) To Create Table Test :

CREATE TABLE Test(`id` int, `name` varchar(20), `reasons` int, `reasonsdescription` varchar(55));

2) To Insert Values In Table:

INSERT INTO Test

(`id`, `name`, `reasons`,`reasonsdescription`)VALUES (1, 'John', 1,''), (2, 'Wiliam', 2,''),

(3, 'Mike', 3,'') ;

3)To Update Columns REASONSDESCRIPTION values from REASON we just need to put WHERE clause as follows:

UPDATE Test SET reasonsdescription='Hello' WHERE reasons=1;

UPDATE Test SET reasonsdescription='World' WHERE reasons=2;

UPDATE Test SET reasonsdescription='SQL' WHERE reasons=3;

ID NAME REASONS RESONSDESCRIPTION 1 John 1 2 William 2 3 Mike 3
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote