05/01/2021, 20:03
Ado Left Join Problem.
05/01/2021, 20:03
feraz
Kodun son halide altta.
Private Sub CommandButton1_Click()
Dim con As Object
Dim rs As Object
Dim Sql As String
Dim s1 As Worksheet, s2 As Worksheet
Set s1 = ThisWorkbook.Sheets("Sayfa1")
Set s2 = ThisWorkbook.Sheets("Sayfa2")
Set con = CreateObject("Adodb.connection")
Set rs = CreateObject("adodb.recordset")
con.Open "provider=microsoft.ace.oledb.12.0;data source=" & ThisWorkbook.FullName & ";extended properties=""Excel 12.0;hdr=yes"""
Sql = "SELECT T1.Ilkbb " & _
"FROM [" & s2.Name & "$] as T2 LEFT JOIN (SELECT aa, First(bb) AS ilkbb " & _
"FROM [" & s1.Name & "$] " & _
"GROUP BY aa) as T1 ON T2.aa = T1.aa;"
rs.Open sql, con, 1, 1
s2.[B:B].Clear
s2.Range("B2").CopyFromRecordset rs
rs.Close: con.Close
Set rs = Nothing: Set con = Nothing: Sql = vbNullString
Set s1 = Nothing: Set s2 = Nothing
End Sub
10/01/2021, 01:10
feraz
Access ilede yaptım kod alttaki gibi çalıştı.Excelde bu şekilde çalışmamıştı kısa olarak
Neyse örnek açısından ekleyeyim dosya.
SELECT Tablo2.aa, First(tablo1.bb) AS İlkbb
FROM Tablo2 LEFT JOIN tablo1 ON Tablo2.aa = tablo1.aa
GROUP BY Tablo2.aa;