2012-04-30 136 views
5

我有一個數據庫表名test123並有name列。它包含像'nir,kal,man'數據現在,當我詢問與select語句表按如下:簡單Select語句不返回任何結果

select * from test123 where name = 'nir,kal,man'; 

但是,這將不會返回任何結果......爲什麼會這樣?我如何編寫查詢以便返回結果? 我正在使用Sql server 2008.

謝謝...!

+1

'nir,kal,man'是單個名字,還是三個不同的名字'nir','kal','man'?我想可能是你在某處丟失了'SPACE'。用'LIKE'運算符檢查查詢。 –

回答

5

=運算符返回精確匹配,因此,如果你的包含數據「如」你需要使用LIKE操作:

select * from test123 where name like '%nir,kal,man%' 

其中%將與任何字符集來代替。

也檢查你正在使用全名瞄準正確的數據庫

select * from yourdb.dbo.test123 where.... 
3

如果尼爾是在第一排在卡爾2行的人,在第三排,那麼你應該寫這樣的查詢

+0

我已經試過這個,但不適合我。 –

+0

只需將test123中select * from test123 where name =('nir','kal','man')''改爲'select * from test123其中名稱IN('nir','kal','man')': - ) –