sql - How do I INSERT INTO SELECT from two different worksheets -


i have sheet bf_upload, has rows in it. i need add data 2 other sheets diamond , variations bf_upload. 2 input worksheets need joined, neither sheet has needed data.

it might easier add column [diamond$].name variations sheet before moving data bf_upload sheet.

sheets diamond , variations have common key [diamond$].code equivalent of [varations$].sku

i think correct join statement.

from [diamond$] inner join [variations$] on [diamond$].code = [varations$].sku 

to add records @ bottom of bf_upload believe need use a:

insert statement 

the code working on included @ bottom of posting. code works sku, regular_price , sale_price fields.

i cannot find way select data 2 sheets less join work.

i have included source data below sample of desired output.

worksheets:

bf_upload has following columns:

sku, post_title, regular_price, sale_price 

variations has following columns, not contiguous:

sku, regular_price, sale price 

diamond has following columns, not contiguous:

code, name 

on diamond sheet code equal sku column on other sheets.

desired output in sheet: bf_upload

sheet: bf_upload: columns not contiguous

sku         post_title             regular_price  sale_price abt00201    biocare, fly trap      11.81          10.69 abt00204    biocare,moth trap       4.95          9.06   abt00415    biocare,fruit fly trap  6.9           12.63  ab00017     acrobird playland 20"   59.81         56.41 ab00018     acrobird playland 24"   79.78         73.24 ab00021     acrobird playland 14"   30.84         24.35 

input worksheets

sheet: diamond: columns not contiguous

sku       name ab00017   acrobird playland 20" ab00018   acrobird playland 24" ab00021   acrobird toddler playland 14" 

sheet: variations: columns not contiguous

sku,      regular_price, sale_price ab00017   59.81          56.41 ab00018   79.78          73.24 ab00021   30.84          24.35 

this code trying working:

private sub cmbvariations2bf_upload_click()      dim objconnection adodb.connection     dim objrecordset adodb.recordset     dim integer     dim strsql string     dim strconn string     dim strtarget string     dim hdrname variant     dim wksname worksheet     dim wksoutput worksheet     dim cnn adodb.connection     dim strconnectionstring string     dim sh worksheet      dim strinsert string      dim lngrow long      dim lastusedcell integer      set sh = sheets("variations")      strtarget = "bf_upload"      pubbf_uploadrows = sheets(strtarget).cells(rows.count, 1).end(xlup).row            set objconnection = new adodb.connection     set objrecordset = new adodb.recordset      strconn = "provider=microsoft.ace.oledb.12.0;" & _                 "data source=" & activeworkbook.fullname & ";" & _                 "extended properties=""excel 12.0;hdr=yes;"";"      objconnection.open strconn      objconnection.execute "insert [bf_upload$] (sku, regular_price, sale_price) select sku, regular_price, sale_price [variations$]"  end sub 

thanks input, craigm

based on description, sql this:

objconnection.execute "insert [bf_upload$] (sku, post_title, regular_price, sale_price) select v.sku, d.[name], v.regular_price, v.sale_price [variations$] v, [diamond$] d d.[code] = v.[sku]" 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -