如何将动态范围字符串文本传递到EXCEL VBA中的SQL查询IN子句 [英] How to pass Dynamic Range string text to SQL query IN clause in EXCEL VBA
本文介绍了如何将动态范围字符串文本传递到EXCEL VBA中的SQL查询IN子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
A
123ABC345
234CDE678
ZSE123MTR
POR123456
结果:
select * from table name where col1 in('123ABC345','234CDE678','ZSE123MTR','POR123456 ')
解决方案
Dim query as String
query =select * from table name where col1 in(
range(A1)。选择
ActiveCell.Value和ActiveCell.Offset(1,0).Value
query = query +'+ Activecell.Value +',
ActiveCell.Offset(1,0)。选择
Wend
query = query +'+ Activecell.Value +')
I have the Dynamic Range String data, need to pass trim the cell and single quote and comma separated to SQL query.
A
123ABC345
234CDE678
ZSE123MTR
POR123456
Result:
select * from table name where col1 in ('123ABC345','234CDE678','ZSE123MTR','POR123456')
解决方案
Dim query as String
query = "select * from table name where col1 in ("
range("A1").Select
While ActiveCell.Value <> "" and ActiveCell.Offset(1, 0).Value <> ""
query = query + "'" + Activecell.Value + "', "
ActiveCell.Offset(1, 0).Select
Wend
query = query + "'" + Activecell.Value + "')"
这篇关于如何将动态范围字符串文本传递到EXCEL VBA中的SQL查询IN子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文