2015-09-01 62 views
0

我明顯在這裏做錯了事。我需要知道如何處理單引號。我有以下SQL代碼不運行:vb腳本和單引號有人可以看我的代碼嗎?

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

不知道是否最終像需求通配符? dim 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% '和c.ID'CUSTID'「 msgbox sql – MiguelH

回答

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 & "'" 
+0

非常感謝你!這讓我瘋狂! – Juniormint

相關問題