From 1c3e290d36f12f17a61bef30e392a52742f04dcc Mon Sep 17 00:00:00 2001 From: xiaochou164 Date: Mon, 14 Aug 2023 10:53:18 +0000 Subject: [PATCH 1/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E6=8A=A5=E8=A1=A8sql/?= =?UTF-8?q?Yield=5F[excel].sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 报表sql/Yield_[excel].sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 报表sql/Yield_[excel].sql diff --git a/报表sql/Yield_[excel].sql b/报表sql/Yield_[excel].sql new file mode 100644 index 0000000..e69de29 From 30354a500ea73d7b64bb4b57e2a992210faaa436 Mon Sep 17 00:00:00 2001 From: xiaochou164 Date: Mon, 14 Aug 2023 10:54:31 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E6=8A=A5=E8=A1=A8sql/?= =?UTF-8?q?Yield=5F[excel].sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 首次提交 --- 报表sql/Yield_[excel].sql | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/报表sql/Yield_[excel].sql b/报表sql/Yield_[excel].sql index e69de29..595153a 100644 --- a/报表sql/Yield_[excel].sql +++ b/报表sql/Yield_[excel].sql @@ -0,0 +1,24 @@ +select + mfgdate 计产日期, + crystalbarno 晶编, + eqpid 炉台号, + subprod 产品规格, + area 车间, + area1 片区, + qclength QC长度, + qcweight 有效重量, + qctime QC检验时间, + adjustcrucible 坩埚厂商, + adjustcruciblecode 坩埚编码, + crusize 热场尺寸, + timeinterval 运行时间, + erpmoname ERP工单号, + moprodname 工单物料编码, + moproddesc 工单物料描述 +from + reportdata.siteonlinecrucibleyield s + where 1=1 + and qctime >= concat(date_format(now()-8.5/24,'%Y-%m-') ,'01 08:30:00') + ##and qctime >= concat(date_format(date_sub(now(),interval 1 month)-8.5/24,'%Y-%m-') ,'01 08:30:00') /*上月第一天 */ + and qctime < concat(date_format(now()-8.5/24,'%Y-%m-%d') ,' 08:30:00') + order by qctime \ No newline at end of file From b1c7c00c29d6ba589f78657be9e855094111c173 Mon Sep 17 00:00:00 2001 From: xiaochou164 Date: Mon, 14 Aug 2023 11:07:07 +0000 Subject: [PATCH 3/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E6=8A=A5=E8=A1=A8sql/?= =?UTF-8?q?BatchNoResistivity=5F[excel].sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 首次提交 --- 报表sql/BatchNoResistivity_[excel].sql | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 报表sql/BatchNoResistivity_[excel].sql diff --git a/报表sql/BatchNoResistivity_[excel].sql b/报表sql/BatchNoResistivity_[excel].sql new file mode 100644 index 0000000..83f81be --- /dev/null +++ b/报表sql/BatchNoResistivity_[excel].sql @@ -0,0 +1,42 @@ +select + order_no 批次号, + resistivity 电阻档位, + min 电阻低值, + case + when min >= 1.9 then '高阻' + else '低阻' + end 高低阻 +from + ( + select + order_no , + resistivity, + case + when resistivity like '>%' then SUBSTRING(resistivity, 5, 7) + when resistivity like '%~%' then SUBSTRING_INDEX(resistivity, '~', 1) + when resistivity like '%-%' then SUBSTRING_INDEX(resistivity, '-', 1) + when resistivity like '<%' then SUBSTRING(resistivity, 5, 7) + when resistivity like '>%' then SUBSTRING(resistivity, 2, 7) + when resistivity like '<%' then SUBSTRING(resistivity, 2, 7) + when resistivity = '未分档' + or resistivity is null then '未分档' + end min + from + mes_sync.mes_recycle_material_storage mrms +union + select + order_no , + resistivity, + case + when resistivity like '>%' then SUBSTRING(resistivity, 5, 7) + when resistivity like '%~%' then SUBSTRING_INDEX(resistivity, '~', 1) + when resistivity like '%-%' then SUBSTRING_INDEX(resistivity, '-', 1) + when resistivity like '<%' then SUBSTRING(resistivity, 5, 7) + when resistivity like '>%' then SUBSTRING(resistivity, 2, 7) + when resistivity like '<%' then SUBSTRING(resistivity, 2, 7) + when resistivity = '未分档' + or resistivity is null then '未分档' + end + from + mes_sync.mes_disposable_qc_task +)a \ No newline at end of file From 03a770d055ababe23421f3a5a39a45d403cffa6b Mon Sep 17 00:00:00 2001 From: xiaochou164 Date: Tue, 15 Aug 2023 11:06:12 +0000 Subject: [PATCH 4/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20vbalinkmysql.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vbalinkmysql.txt | 109 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 vbalinkmysql.txt diff --git a/vbalinkmysql.txt b/vbalinkmysql.txt new file mode 100644 index 0000000..72e1442 --- /dev/null +++ b/vbalinkmysql.txt @@ -0,0 +1,109 @@ +Public conn As ADODB.Connection '-----定义数据库连接 Public 方便每个SUB使用 不需要重复定义 +Public RES As ADODB.Recordset '-----定义结果集 结果集和二维表很类似 +Public Sign As String +Dim row, col As Integer +Dim Sql As String +Public Sub closeConn() +On Error Resume Next + If conn Is Nothing Then Exit Sub + conn.Close + Set conn = Nothing +End Sub + +'----连接数据库 +Public Sub AutoRun() + Call closeConn + On Error Resume Next + Dim strDBinf As String + + Application.StatusBar = "正在连接数据库……" + + If conn Is Nothing Then + Set conn = New ADODB.Connection + Set RES = CreateObject("ADODB.Recordset") + + strDBinf = "DSN=mysqlinklexcel32" '标准语句 + Call conn.Open(strDBinf) + + If VBA.Err.Number <> 0 Then + strDBinf = "DSN=mysqlinklexcel64" '标准语句 + VBA.MsgBox "32位DSN连接失败,尝试使用mysqlinklexcel6连接!" + Call conn.Open(strDBinf) + End If + + If VBA.Err.Number > 1 Then + VBA.MsgBox "连接异常,请检查DB环境!" + Set conn = Nothing + End If + Application.StatusBar = "数据库连接成功" + End If +End Sub +Sub 拉取电阻信息() +t = Timer + +Application.ScreenUpdating = False +Application.Calculation = xlCalculationManual + +Sql = "SELECT order_no,resistivity, " +Sql = Sql + "case when resistivity LIKE '>%' then SUBSTRING(resistivity,5,7) " +Sql = Sql + " when resistivity LIKE '%~%' then SUBSTRING_INDEX(resistivity,'~',1) " +Sql = Sql + " when resistivity LIKE '%-%' then SUBSTRING_INDEX(resistivity,'-',1) " +Sql = Sql + " when resistivity LIKE '<%' then SUBSTRING(resistivity,5,7) " +Sql = Sql + " when resistivity LIKE '>%' then SUBSTRING(resistivity,2,7) " +Sql = Sql + " when resistivity LIKE '<%' then SUBSTRING(resistivity,2,7) " +Sql = Sql + " when resistivity = '未分档' OR resistivity IS null then '未分档' end " +Sql = Sql + " from mes_sync.mes_disposable_qc_task " +Sql = Sql + " Union " +Sql = Sql + " SELECT order_no,resistivity, " +Sql = Sql + " case when resistivity LIKE '>%' then SUBSTRING(resistivity,5,7) " +Sql = Sql + " when resistivity LIKE '%~%' then SUBSTRING_INDEX(resistivity,'~',1) " +Sql = Sql + " when resistivity LIKE '%-%' then SUBSTRING_INDEX(resistivity,'-',1) " +Sql = Sql + " when resistivity LIKE '<%' then SUBSTRING(resistivity,5,7) " +Sql = Sql + " when resistivity LIKE '>%' then SUBSTRING(resistivity,2,7) " +Sql = Sql + " when resistivity LIKE '<%' then SUBSTRING(resistivity,2,7) " +Sql = Sql + " when resistivity = '未分档' OR resistivity IS null then '未分档' end " +Sql = Sql + " from mes_sync.mes_recycle_material_storage; " + + + +Call AutoRun '------获取数据库连接 + +Application.StatusBar = "正在拉取批次信息" +RES.Open Sql, conn '-----执行strSql 获得结果集 + +Application.StatusBar = "正在复制批次信息到表格" +Sheets("电阻信息").Cells(2, 1).CopyFromRecordset RES + +RES.Close '-------关闭结果集 必须要做的 + +Call closeConn + +尾行 = Cells(Rows.Count, "A").End(xlUp).row + +Application.StatusBar = "正在判断高低阻信息" +For i = 2 To 尾行 + 电阻 = Sheets("电阻信息").Cells(i, 3).Value + On Error Resume Next + + If 电阻 = "未分档" Then + Sheets("电阻信息").Cells(i, 4).Value = "低阻" + Else + If 电阻 >= 1.9 Then + Sheets("电阻信息").Cells(i, 4).Value = "高阻" + Else: Sheets("电阻信息").Cells(i, 4).Value = "低阻" + End If + End If +Next + + + +Application.ScreenUpdating = True +Application.Calculation = xlCalculationAutomatic + +Application.StatusBar = "拉取完成" + +MsgBox ("本次更新共花费:" & Format(Timer - t, "0.00") & "s!") +Application.StatusBar = False +End Sub + + From a3436b59ad2b4e3fd97e7b847407fc7f9119aa39 Mon Sep 17 00:00:00 2001 From: xiaochou164 Date: Tue, 15 Aug 2023 11:07:13 +0000 Subject: [PATCH 5/6] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20vbalinkmysql.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vbalinkmysql.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vbalinkmysql.txt b/vbalinkmysql.txt index 72e1442..ffbd5ce 100644 --- a/vbalinkmysql.txt +++ b/vbalinkmysql.txt @@ -27,12 +27,12 @@ Public Sub AutoRun() If VBA.Err.Number <> 0 Then strDBinf = "DSN=mysqlinklexcel64" '标准语句 - VBA.MsgBox "32位DSN连接失败,尝试使用mysqlinklexcel6连接!" + VBA.MsgBox "32位DSN连接失败,尝试使用mysqllinkexcel6连接!" Call conn.Open(strDBinf) End If If VBA.Err.Number > 1 Then - VBA.MsgBox "连接异常,请检查DB环境!" + VBA.MsgBox "连接异常,请检查DB环境!" Set conn = Nothing End If Application.StatusBar = "数据库连接成功" From 782cddb18b1698b6b8082dcd6726a324beaa73b0 Mon Sep 17 00:00:00 2001 From: xiaochou164 Date: Tue, 15 Aug 2023 11:10:31 +0000 Subject: [PATCH 6/6] =?UTF-8?q?=E5=88=A0=E9=99=A4=20vbalinkmysql.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vbalinkmysql.txt | 109 ----------------------------------------------- 1 file changed, 109 deletions(-) delete mode 100644 vbalinkmysql.txt diff --git a/vbalinkmysql.txt b/vbalinkmysql.txt deleted file mode 100644 index ffbd5ce..0000000 --- a/vbalinkmysql.txt +++ /dev/null @@ -1,109 +0,0 @@ -Public conn As ADODB.Connection '-----定义数据库连接 Public 方便每个SUB使用 不需要重复定义 -Public RES As ADODB.Recordset '-----定义结果集 结果集和二维表很类似 -Public Sign As String -Dim row, col As Integer -Dim Sql As String -Public Sub closeConn() -On Error Resume Next - If conn Is Nothing Then Exit Sub - conn.Close - Set conn = Nothing -End Sub - -'----连接数据库 -Public Sub AutoRun() - Call closeConn - On Error Resume Next - Dim strDBinf As String - - Application.StatusBar = "正在连接数据库……" - - If conn Is Nothing Then - Set conn = New ADODB.Connection - Set RES = CreateObject("ADODB.Recordset") - - strDBinf = "DSN=mysqlinklexcel32" '标准语句 - Call conn.Open(strDBinf) - - If VBA.Err.Number <> 0 Then - strDBinf = "DSN=mysqlinklexcel64" '标准语句 - VBA.MsgBox "32位DSN连接失败,尝试使用mysqllinkexcel6连接!" - Call conn.Open(strDBinf) - End If - - If VBA.Err.Number > 1 Then - VBA.MsgBox "连接异常,请检查DB环境!" - Set conn = Nothing - End If - Application.StatusBar = "数据库连接成功" - End If -End Sub -Sub 拉取电阻信息() -t = Timer - -Application.ScreenUpdating = False -Application.Calculation = xlCalculationManual - -Sql = "SELECT order_no,resistivity, " -Sql = Sql + "case when resistivity LIKE '>%' then SUBSTRING(resistivity,5,7) " -Sql = Sql + " when resistivity LIKE '%~%' then SUBSTRING_INDEX(resistivity,'~',1) " -Sql = Sql + " when resistivity LIKE '%-%' then SUBSTRING_INDEX(resistivity,'-',1) " -Sql = Sql + " when resistivity LIKE '<%' then SUBSTRING(resistivity,5,7) " -Sql = Sql + " when resistivity LIKE '>%' then SUBSTRING(resistivity,2,7) " -Sql = Sql + " when resistivity LIKE '<%' then SUBSTRING(resistivity,2,7) " -Sql = Sql + " when resistivity = '未分档' OR resistivity IS null then '未分档' end " -Sql = Sql + " from mes_sync.mes_disposable_qc_task " -Sql = Sql + " Union " -Sql = Sql + " SELECT order_no,resistivity, " -Sql = Sql + " case when resistivity LIKE '>%' then SUBSTRING(resistivity,5,7) " -Sql = Sql + " when resistivity LIKE '%~%' then SUBSTRING_INDEX(resistivity,'~',1) " -Sql = Sql + " when resistivity LIKE '%-%' then SUBSTRING_INDEX(resistivity,'-',1) " -Sql = Sql + " when resistivity LIKE '<%' then SUBSTRING(resistivity,5,7) " -Sql = Sql + " when resistivity LIKE '>%' then SUBSTRING(resistivity,2,7) " -Sql = Sql + " when resistivity LIKE '<%' then SUBSTRING(resistivity,2,7) " -Sql = Sql + " when resistivity = '未分档' OR resistivity IS null then '未分档' end " -Sql = Sql + " from mes_sync.mes_recycle_material_storage; " - - - -Call AutoRun '------获取数据库连接 - -Application.StatusBar = "正在拉取批次信息" -RES.Open Sql, conn '-----执行strSql 获得结果集 - -Application.StatusBar = "正在复制批次信息到表格" -Sheets("电阻信息").Cells(2, 1).CopyFromRecordset RES - -RES.Close '-------关闭结果集 必须要做的 - -Call closeConn - -尾行 = Cells(Rows.Count, "A").End(xlUp).row - -Application.StatusBar = "正在判断高低阻信息" -For i = 2 To 尾行 - 电阻 = Sheets("电阻信息").Cells(i, 3).Value - On Error Resume Next - - If 电阻 = "未分档" Then - Sheets("电阻信息").Cells(i, 4).Value = "低阻" - Else - If 电阻 >= 1.9 Then - Sheets("电阻信息").Cells(i, 4).Value = "高阻" - Else: Sheets("电阻信息").Cells(i, 4).Value = "低阻" - End If - End If -Next - - - -Application.ScreenUpdating = True -Application.Calculation = xlCalculationAutomatic - -Application.StatusBar = "拉取完成" - -MsgBox ("本次更新共花费:" & Format(Timer - t, "0.00") & "s!") -Application.StatusBar = False -End Sub - -