2010-10-17 71 views
1

我有一個表(託管在數據庫SQL Server中),我已經存儲了產品。 上週插入了一些產品的人,而不是用「Enter」創建新行(tinyMCE會在描述中創建一個</br>標籤),她輸入了「Space」創建空白區域(她雖然鍵入了空格,但創建了新的當它進入新的線時,真的很愚蠢)。SQL - 需要幫助建立一個選擇查詢

所以,我的記錄是這樣的:

Description: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;

現在我試圖創建搜索該記錄的查詢,但我認爲我在使用LIKE運算符錯誤的方法。

SELECT * From ProductsDescription WHERE Description LIKE '%&nbsp;&nbsp;' 

它返回0行。該查詢中有任何錯誤?

感謝

+0

這裏有一個類似的問題 - 你有沒有評論這個答案呢? http://stackoverflow.com/questions/457701/best-way-to-strip-html-tags-from-a-string-in-sql-server – 2010-10-17 02:02:54

+0

(直接鏈接到一些額外的SQL爲此)http:///lazycoders.blogspot.com/2007/06/stripping-html-from-text-in-sql-server.html – 2010-10-17 02:04:09

+0

謝謝鮑勃,之前沒有看到答案。 – 2010-10-17 02:18:37

回答

3
  1. 進去擺脫空間單引號。
  2. 追加另一個%

例如爲:

SELECT * From ProductsDescription WHERE Description LIKE '%&nbsp;&nbsp;%'; 

編輯:
忽略上述點#1。正如@Hippo在評論中指出的那樣,只是一個格式問題。我編輯了這個問題來刪除多餘的空格。

+2

在Guilherme的問題中,空格並不是真的存在 - 嘗試選擇查詢並將其粘貼到某處。 – AbdullahC 2010-10-17 02:04:55

+0

很好,@Hippo。我編輯了這個問題。 – bernie 2010-10-17 02:07:04

+0

問題是在最後的其他%。謝謝 – 2010-10-17 02:16:25

3

嘗試增加在年底另一個百分號爲好,如果最後一個字符不是一個分號,即:

SELECT * From ProductsDescription WHERE Description LIKE '%&nbsp;&nbsp;%' 
1
select * from ProductsDescription where description like '%nbsp%' 
+0

這個搜索可能會導致誤報。包含至少兩個' '會更好,因爲您知道所有結果都會包含該結果。 – AbdullahC 2010-10-17 02:08:35

+0

重點是添加第二個%。遵循你的邏輯,爲什麼不添加3  而不是? – Alex 2010-10-17 02:10:44

+0

由於你也剝離了& and ;,所以不太清楚這點是什麼。那些還有問題嗎?我在添加3  時看不到問題 - 但OP指定了2,因此您可以將其保留。 – AbdullahC 2010-10-17 02:14:50