Joseph John
Joseph John

Reputation: 1

Copy all the values from table1 to table2 only if condition met

Let's say var_Environment = QA1,QA2.

I have two tables table 1 and table 2. Table 1 has some column name var_Environment =QA1; where as table 2 does have the same column name but no values

Now my task is, I need to copy all the values from table1 to table2 only if condition meets var_Environment =QA2 How will I perform this operation ? Can I use Union All with some condition? Can someone help?

Upvotes: 0

Views: 68

Answers (1)

nbk
nbk

Reputation: 49375

You can use INSERT INTO SELECT like below.

The WHERE clause may need adjustment, so run the the SELECT query by itself to check if the correct rows are selected.

INSERT INTO table2
SELECT var_Environment 
FROM Table1
WHERE var_Environment  LIKE '%QA2%'

Upvotes: 1

Related Questions