简体   繁体   中英

Dealing with single quotes in excel vba sql queries

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM