我显然在这里做错了什么。我需要知道应该如何处理单引号。我有以下不运行的SQL代码:
sql = "Select C.ID, cc.contact_email as Email, cc.web_user_id from customer c
Inner join CUSTOMER_CONTACT cc ON "
sql = sql & "c.ID = cc.customer_ID Where cc.web_user_id like "' %O%"'"
and c.ID like "' & CUSTID & "'" "
任何帮助将不胜感激。我在网上看到很多关于如何处理双引号而没有关于单引号的内容。
答案 0 :(得分:0)
sql = "SELECT C.ID, cc.contact_email as Email, cc.web_user_id " & _
" FROM customer c Inner join CUSTOMER_CONTACT cc ON c.ID = cc.customer_ID " & _
" WHERE cc.web_user_id like '%O%' and c.ID like '" & CUSTID & "' "
让我们看一个简单的流程示例。我们从一个sql命令开始,该命令将包含来自变量
的数据select * from tblData where name='variable'
第一步,引用命令并分配给变量
sql = "select * from tblData where name='variable'"
第二步,剪切需要插入变量的位置。单引号不在变量中(对于此示例),因此它们保留在字符串
中sql = "select * from tblData where name='" | "'"
第三步,在切割位置连接变量内容
sql = "select * from tblData where name='" & variable & "'"