【问题标题】:Simple Select statement does not return any result简单的 Select 语句不返回任何结果
【发布时间】:2012-05-09 21:18:27
【问题描述】:

我有一个数据库表名称test123 和列name。它包含像'nir,kal,man' 这样的数据,现在,当我使用 select 语句查询表时,如下所示:

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

但这不会返回任何结果...为什么会这样。?我如何编写查询以便返回结果? 我使用的是 Sql server 2008。

谢谢...!

【问题讨论】:

  • nir,kal,man是一个名字,还是三个不同的名字nir,kal,man?!!!我想你可能在某个地方错过了SPACE。使用LIKE 运算符检查查询..

标签: sql database sql-server-2008


【解决方案1】:

= 运算符返回完全匹配,因此如果您的单元格包含需要使用 LIKE 运算符的数据“喜欢”:

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

% 将被替换为任意字符集。

同时使用全名检查您的目标数据库是否正确

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

【讨论】:

    【解决方案2】:

    如果 Nir ​​在第一行 Kal 在第二行,而 man 在第三行,那么你应该这样写查询

    select * from test123 where name in ('nir','kal','man')
    

    【讨论】:

    • 只需将select * from test123 where name = ('nir','kal','man') 更改为select * from test123 where name IN ('nir','kal','man') :-)
    猜你喜欢
    • 1970-01-01
    • 2012-08-23
    • 1970-01-01
    • 2011-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    相关资源
    最近更新 更多