1

I'm trying to do this:

<cfquery name="GetAccountsAndStocks" dbtype="query">
    Select STOCK, CUST_NUMBER
      From GetExtractionData
     WHERE CUST_NUMBER NOT LIKE  '\''
</cfquery>

The cust_number is either ' (for blank) or ' followed by a 10 character string.

I thought I should escape the ', but it doesn't work. How can I do this?

4

2 回答 2

2

要转义单引号,请使用''(两个单引号),例如:

WHERE cust_number NOT LIKE ''''

但是,我对查询中的NOT LIKEin query 的使用不太熟悉;通常会使用通配符(例如%):

WHERE cust_number NOT LIKE '%''%'

在您的情况下,cust_number如果打算为空白,您会说是单引号。您不会NOT LIKE为此使用,而只是<>

WHERE cust_number <> ''''
于 2015-03-06T15:27:32.400 回答
1

cfqueryparam 用 q of q 和数据库查询同样很好地解决了这个问题。

于 2015-03-06T16:45:34.567 回答