asp.net - SQL WHERE 语句 100% 不起作用

标签 asp.net sql sql-server sql-server-2005

我想返回 Worldwide = yesvisible = yes 且位于 的值州 = 佛罗里达,但这不会返回全局的所有其他值

select  * from Table1
where (visible = 'yes' and State = 'Florida') or Worldwide= 'yes'
order by ID DESC

编辑:我的坏处

抱歉,各位,这个声明确实有效!我在语句中选择了 TOP 8 *,这就是为什么它没有返回所有记录!当我把前 8 名拿出来时,它成功了!我的错!

最佳答案

使用以下脚本,查询输出预期的内容。

创建数据

DECLARE @Table1 TABLE (
  ID INTEGER IDENTITY(1, 1)
  , State VARCHAR(32)
  , Visible VARCHAR(32)
  , WorldWide VARCHAR(32)
)

INSERT INTO @Table1
SELECT 'Florida', 'Yes', 'Yes'  
UNION ALL SELECT 'Florida', 'Yes', 'No'  
UNION ALL SELECT 'Florida', 'No', 'Yes'  
UNION ALL SELECT 'Florida', 'No', 'No'  
UNION ALL SELECT 'Other State', 'Yes', 'Yes'  
UNION ALL SELECT 'Other State', 'Yes', 'No'  
UNION ALL SELECT 'Other State', 'No', 'Yes'  
UNION ALL SELECT 'Other State', 'No', 'No'  

选择

SELECT  *
FROM    @Table1
WHERE   (Visible = 'Yes' AND State = 'Florida') OR WorldWide = 'Yes'

输出

ID  State           Visible WorldWide
1   Florida          Yes    Yes
2   Florida          Yes    No
3   Florida          No     Yes
5   Other State      Yes    Yes
7   Other State      No     Yes

关于asp.net - SQL WHERE 语句 100% 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4623557/

相关文章:

asp.net - 是否可以将 Azure 连接到 google 云端硬盘?

asp.net - 是否有理由编写自己的身份验证而不是使用 Forms Security

javascript - 无法在 gridview 内单击按钮时触发 jQuery 函数

mysql - 使用子查询和内连接插入

mysql - 如何查找一个字段的内容在另一个字段的任何行中的 MySQL 记录

python - 如何创建内部 Web 表单/应用程序来收集用户输入并存储它

c# - 通过 sql profiler 测试 Web API 服务?

asp.net - ListItem 附加自定义值

SQL Server POWER 函数

sql-server - 使用 SQL Server 进行实时聚合和反规范化的架构推荐