|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Set SH0 = Worksheets("Sheet1")
- SH0.Range("A4:F65536").ClearContents
-
- Str_coon = "HDR=yes';Data Source =" & ThisWorkbook.FullName '//OFFICE2003,2007 通用
- StrSQL = ""
- StrSQL = StrSQL & "SELECT 姓名,学籍辅号,国网学号,身份证号码,户籍地,民族"
- StrSQL = StrSQL & " FROM ("
- StrSQL = StrSQL & "SELECT A.姓名,A.学籍辅号,A.国网学号,A.身份证号码,A.户籍地,A.民族"
- StrSQL = StrSQL & ",B.姓名 AS 条件"
- StrSQL = StrSQL & " FROM ("
- StrSQL = StrSQL & "SELECT 姓名,学籍辅号,国网学号,身份证号码,户籍地,民族"
- StrSQL = StrSQL & " FROM [" & SH0.Name & "$H3:M]"
- StrSQL = StrSQL & ") AS A LEFT JOIN ("
- StrSQL = StrSQL & "SELECT 姓名,学籍辅号,国网学号,身份证号码,户籍地,民族"
- StrSQL = StrSQL & " FROM [" & SH0.Name & "$N3:S]"
- StrSQL = StrSQL & ") AS B ON A.姓名=B.姓名 AND A.身份证号码=B.身份证号码"
- StrSQL = StrSQL & " AND A.学籍辅号=B.学籍辅号 AND A.国网学号=B.国网学号 AND A.民族=B.民族"
-
- StrSQL = StrSQL & " AND ("
- Rem 或者:户籍地包含关系
- StrSQL = StrSQL & "INSTR(B.户籍地,A.户籍地)>0"
- Rem 或者:中招网中“外省户籍”对应国网中不含“长乐市”的也较验通过
- StrSQL = StrSQL & "OR (A.户籍地='外省户籍' AND INSTR(B.户籍地,'长乐市')=0)"
- Rem 或者:中招网户籍地中如遇“香港、台湾、澳门”对应国网含“长乐市”户籍较验也通过
- StrSQL = StrSQL & "OR (INSTR(A.户籍地,'香港')+INSTR(A.户籍地,'台湾')+INSTR(A.户籍地,'澳门')>0 AND INSTR(B.户籍地,'长乐市')>0)"
- StrSQL = StrSQL & ")"
-
- StrSQL = StrSQL & ") WHERE NOT 条件 IS NULL AND LEN(条件)>0"
-
- SQLARR = GET_SQL_To_Arr(StrSQL, Str_coon, False)
- SH0.Range("A4").Resize(UBound(SQLARR, 1) + 1, UBound(SQLARR, 2) + 1) = SQLARR
复制代码 |
|