General discussion

Locked

SQL Query

By Kris2003 ·
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?

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by barneyrubble318 In reply to SQL Query

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

Collapse -

Inserting rows into Table1

by abr In reply to SQL Query

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

Back to Software Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums