3

I want to know if there is a way to achieve this. I have two table, I want to move data from one table to another table.

TableA:
ID  Name  Option
----------------------
1  First   Add into box
2  Second  Don't Add
3  Third   Add into box

TableB
ID Name    Option          Status
--------------------------------
1  First   Add into box    Approved 
2  Second  Don't Add       Reject
3  Third   Add into box    Approved 

I want to insert data from TableA to tableB but tableB have one more column, where the value of it depends on option column data. If column value is Add into box then it should be inserted as approved into TableB else Reject has to be inserted.

3
  • MySQL and SSMS (SQL Server Management Studio) have no relationship. As it's name suggests, SSMS is for SQL Server, which is a completely different product to MySQL. What RDBMS are you really using? Commented Jun 20, 2022 at 10:25
  • 1
    As for the problem, use a CASE expression. Commented Jun 20, 2022 at 10:26
  • There is definitely a way to achieve this it's quite trivial but please first tag the correct database Commented Jun 20, 2022 at 10:32

1 Answer 1

2

If you are using MSSQL, the below query would work.

Insert into TableB (Id,Name, Option, Status) 
select Id,Name, Option, CASE when Option = 'Add into box'  then 'Approved' ELSE 'Rejected' END
From TableA
Sign up to request clarification or add additional context in comments.

3 Comments

Hello @Ankitha, Thank you! it worked, didn't know this was that simple.
@Mike since this appears to be SQL Server, I will tag the correct database. Please make sure you do thisin future.
@Nick.McDermaid, Thank you! I was actually confused with these terms: sql-server and MySql and sql.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.