SQL INSERT statement?

Status
Not open for further replies.

krtola

Ars Scholae Palatinae
1,205
Hi guys,

I am trying to do a simple insert statement like bellow.

Code:
insert into user_customer
values (149, 1001, 3)

The problem is i need to perform this query about 85 times because the value '1001' is different for each entry.

What is the right way of typing this SQL query to accomplish the above without having to do it one at the time?

Regards,
Nermin
 

fitten

Ars Legatus Legionis
55,634
Subscriptor++
Depends on what you're trying to do...

If you're just copying values:

insert into user_customer (uc_col1, uc_col2, uc_col3)
select ot_col1, ot_col2, ot_col3 from other_table where...

If you're doing something more complex, like updating values in user_customer from values in other_table:

update user_customer
set uc_col2 = ot_col2, uc_col3 = ot_col3
from user_customer join other_table on uc_col1 = ot_col1
where...
 

krtola

Ars Scholae Palatinae
1,205
fitten":3r15a1jk said:
Depends on what you're trying to do...

If you're just copying values:

insert into user_customer (uc_col1, uc_col2, uc_col3)
select ot_col1, ot_col2, ot_col3 from other_table where...

If you're doing something more complex, like updating values in user_customer from values in other_table:

update user_customer
set uc_col2 = ot_col2, uc_col3 = ot_col3
from user_customer join other_table on uc_col1 = ot_col1
where...

Thank for the explanation, i got it figured out now and it works.

Thank you for your help on this guys,
Nermin
 
Status
Not open for further replies.