VBA 把Excel表当做一个大数据库来操作

VBA 把Excel表当做一个大数据库来操作

python 复制代码
Sub SqlQueryBJD(strBillNo As String)

Dim strSql As String
Dim arrCol() As String
Dim strLineWhere
Dim arrWhere() As String
Dim strWhereVal As String

Dim strResultShowRng As String
Dim strWhereRng As String
Dim strShowResultRowRng As String
Dim strShowResultRowMsg As String

Dim strSqlSb As String
Dim wsDbQ As Worksheet
Dim sqlSb As New StringBulider

On Error GoTo er:

'日期,单号,直接费用,管理费,税率,税金,合计,报价单抬头,工程名称,提交单位,客户名称,地址,电话,施工面积,备注,项目类别,项目名称,数量,单位,材料单价,材料合价,人工单价,人工合价,工艺说明,材料成本,材料加价,材料利润,人工成本,人工加价,人工利润,单项利润人工单价    人工合价    工艺说明    材料成本    材料加价    材料利润    人工成本    人工加价    人工利润    单项利润

sqlSb.Append ("select rowNo,项目类别,项目名称,数量,单位,材料单价,材料合价,工艺说明")
sqlSb.Append (" from (")

sqlSb.Append ("select rowNo,项目类别&0 as 项目类别,项目名称,'t1' as 数量,'' as 单位,'' as 材料单价,'' as 材料合价,'' as 工艺说明 from [报价单记录$B1:AG]")
sqlSb.Append (" where 项目名称<>'' And cdbl(iif(数量 is null,0,数量))=0 ")
sqlSb.Append (" and 单号='" & strBillNo & "'")

sqlSb.Append ("union all select rowNo,项目类别&1,项目名称,数量,单位,材料单价,材料合价,工艺说明 from [报价单记录$B1:AG]")
sqlSb.Append (" where 项目名称<>'' And cdbl(iif(数量 is null,0,数量))>0")
sqlSb.Append (" and 单号='" & strBillNo & "'")

sqlSb.Append ("union all select max(rowNo),项目类别&2,'小计' as 项目名称,'t2' as 数量,'' as 单位,sum(iif(材料合价 is null,0,材料合价)) as 材料单价,'' as 材料合价,'' as 工艺说明 from [报价单记录$B1:AG]")
sqlSb.Append (" where 项目名称<>'' And cdbl(iif(数量 is null,0,数量))>0")
sqlSb.Append (" and 单号='" & strBillNo & "'")
sqlSb.Append (" group by 项目类别")

sqlSb.Append (" ) as tbz")

sqlSb.Append (" order by rowNo,项目类别")

strSql = sqlSb.ToString()

strResultShowRng = "A1:P?"
strWhereRng = "Format(日期,'yyyy-MM-dd')>=:B2:D|Format(日期,'yyyy-MM-dd')<=:C2:D|单号 like:B3:S|工程名称 like:E2:S|客户名称 like:E3:S|地址 like:G2:S|电话 like:G3:S"
strShowResultRowRng = ""
strShowResultRowMsg = ""
 

 
    Set wsDbQ = Worksheets("tempBjqdData")
     
'    arrCol = Split(strWhereRng, "|")
'
'
'    For Each strLineWhere In arrCol
'      arrWhere = Split(strLineWhere, ":")
'      strWhereVal = wsDbQ.Range(arrWhere(1)).Value
'
'      If Trim(strWhereVal) <> "" Then
'        strSqlSb = strSqlSb & " and " & arrWhere(0) & GetSqlVal(arrWhere(0), strWhereVal, arrWhere(2))
'      End If
'    Next strLineWhere
    
    Call SqlADODBQuery("tempBjqdData", strResultShowRng, strSql, strShowResultRowRng, strShowResultRowMsg)
    

 Exit Sub
er:
 MsgBox err.Description
 
End Sub
相关推荐
前方一片光明4 小时前
SQL SERVER——生成sql:删除所有log表中,user_name是某用户的数据
数据库·sql·oracle
Gauss松鼠会5 小时前
【GaussDB】在duckdb中查询GaussDB的数据
数据库·sql·database·gaussdb
虹科网络安全5 小时前
艾体宝洞察 | Redis vs ElastiCache:哪个更具成本效益?
数据库·redis·缓存
自在极意功。5 小时前
MyBatis 动态 SQL 详解:从基础到进阶实战
java·数据库·mybatis·动态sql
老邓计算机毕设5 小时前
SSM校园订餐系统7z0dm(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面
数据库·菜品管理系统·ssm 框架·ssm 框架开发·校园线上订餐平台
sxlishaobin5 小时前
MySQL- explain
数据库·mysql
曹牧6 小时前
Oracle:判断一个字符串出现次数
数据库·oracle
源代码•宸6 小时前
Leetcode—620. 有趣的电影&&Q3. 有趣的电影【简单】
数据库·后端·mysql·算法·leetcode·职场和发展
快乐肚皮6 小时前
MySQL递归CTE
java·数据库·mysql·递归表达式
2301_800256116 小时前
地理空间数据库中的CPU 和 I/O 开销
数据库·算法·oracle