Discussion Locked

SQL Query

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I was wondering if someone can tell me what I'm doing wrong here.

insert into Table1
(Column1)
select N.Column2
from Table2 N
, Table1 A
where N.Column3 = A.Column3

This statement is meant to insert the value in Column2 into another table with column name being Column1 when both Column3 numbers are equal in both tables.

When I run the script it says 727 rows affected, but when I run a select statement to see the results, it all looks exactly the same. What is it updating? And why isn't inserting the data into column1?

2 replies

by barneyrubble318

Sounds like you want an update select rather than an insert into. Insert into is creating new rows in Table1.

by abr

Try, this. I am assuming that you need to insert new rows in to Table1 based on rows in Tables2 and 1

insert into Table1
(Column1)= N.Column2
from Table2 N
, Table1 A
where N.Column3 = A.Column3

If you mean to update rows in Table1 based on Table2, you need to try

update Table1
set Column1= N.Column2
from Table2 N
, Table1 A
where N.Column3 = A.Column3

This discussion is closed to new replies.