SQL Server 中的三值逻辑示例 [英] Example of three valued logic in SQL Server

查看:31
本文介绍了SQL Server 中的三值逻辑示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 SQL 使用三值逻辑,但我无法理解如何在实践中使用它,尤其是为什么 TRUE ||NULL = TrueFALSE &&NULL = False 而不是评估为 null.

I understand that SQL uses three valued logic but I am having trouble understanding how to use this in practice, especially why TRUE || NULL = True and FALSE && NULL = False instead of evaluating to null.

以下是适用于 SQL Server 的三个值真值表:

Here are the three valued truth tables that apply to SQL Server:

我在网上找到了对三值逻辑的一些解释,但我找不到任何实际使用的代码示例.有人可以向我展示一个使用三值逻辑的代码示例来帮助我更好地理解这一点吗?

I found a couple explanations of three valued logic online but I cannot find any real code examples of this in use. Can someone show me a code example using three valued logic to help me understand this a little better?

推荐答案

TRUE || 的例子NULL = True 将是

declare @x as int = null;
if 1=1 or @x/1=1
    print 'true'

FALSE && 的示例NULL = False 将是

declare @x as int = null;
if not(1=2 and @x/1=1)
    print 'false'

这篇关于SQL Server 中的三值逻辑示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆