Sub yy2() Dim arr() With Worksheets("行列转换3") Set CNN = CreateObject("adodb.connection") CNN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;hdr=yes;';Data Source=" & ThisWorkbook.FullName .Range("g2:n10").ClearContents r = .Range("a65536").End(xlUp).Row Sheets("行列转换3").[a1:e18].Name = "tbl" sql1 = "select distinct 姓名 ,(select top 1 调薪时间 from tbl where 姓名=a.姓名 ),(select top 1 调整后薪资 from tbl where 姓名=a.姓名 )" j = 1 For i = 1 To 13
sql2 = " ,(select top 1 调薪时间 from tbl where 姓名=a.姓名 and 调薪时间 not in (select top " & i & " 调薪时间 from tbl where 姓名=a.姓名 )),(select top 1 调整后薪资 from tbl where 姓名=a.姓名 and 调整后薪资 not in (select top " & i & " 调整后薪资 from tbl where 姓名=a.姓名 )) " ReDim Preserve arr(0 To j) arr(i) = sql2 j = j + 1 Next sql3 = Join(arr, "") sql4 = " from tbl a" Sql = sql1 & sql3 & sql4 'MsgBox Sql .Range("g2").CopyFromRecordset CNN.Execute(Sql) End With End Sub
|