本文介绍了在Excel VBA SQL查询中处理单引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用excel sql查询根据我在下拉框中所做的选择从后端获取数据.但是,如果下拉框中的值只有一个quote('),我的sql查询将无法正常工作.例如-男装.请建议我一种解决此问题的方法
I am using excel sql queries to fetch data from the backend according to the selection i make in a dropdown box.However my sql queries are not working in cases where there is a single quote(') in the dropdown box value. For example-- Men's Wear . Please suggest me a way to deal with this problem
SQL = "select Segment,Weeks,Value from [Category performance data$] where Departments='" & Sheet3.Range("Dept_name").Value & _
"' and Metric ='Total Spend' group by Segment,Weeks,Value"
Call execQry
推荐答案
Departments='" & replace(Sheet3.Range("Dept_name").Value, "'", "''") & _ "' and Metric
这篇关于在Excel VBA SQL查询中处理单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!