SQL CE 选择语句中的反转布尔(位)值 [英] Reverse boolean (bit) value in SQL CE select statement

查看:34
本文介绍了SQL CE 选择语句中的反转布尔(位)值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个从 SQL CE 数据库中获取表信息的查询,准备好放入 c#,稍后导出到 XML.我需要将其中一列命名为带有布尔值的IDENT"(很明显,用于表示它是否是标识列).

I am trying to write a query that gets table information from a SQL CE database, ready to be put in c#, later to be exported to XML. I need one of the columns to be named 'IDENT' with a boolean value (to represent whether or not it is the identity column, obviously).

为此,我正在检查 AUTOINC_SEED 列是否为空,如下所示:

For this, I am checking if the AUTOINC_SEED column is null, as follows:

select isnull(AUTOINC_SEED) as IDENT from information_schema.columns

但是,这对非标识列返回 TRUE,对标识列返回 FALSE!有什么办法可以反转select语句中的布尔值吗?

However, this returns TRUE for non-identity columns and FALSE for identity columns! Is there any way to reverse the boolean value inside the select statement?

我知道我可以做一个 case 语句来解决这个特定的问题,但这让我对在 SQL 中反转布尔值(位)感到好奇.

I'm aware I could do a case statement to solve this particular problem, but it got me curious about inverting boolean (bit) values in SQL.

推荐答案

SQL Server 中的克拉 (^) 是 按位异或运算符.

The carat (^) in SQL Server is the bitwise exclusive OR operator.

由于1 ^ 1等于0,而1 ^ 0等于1,你可以这样做:

Since 1 ^ 1 equals 0, and 1 ^ 0 equals 1, you can just do:

SELECT (1 ^ [YourBitColumn]) as InverseBit

我也没有方便的 SQL CE,但由于 SQL CE 似乎有这个,我相信以下查询应该可以解决问题:

I don't have SQL CE handy either, but since SQL CE appears to have this, I believe the following query should do the trick:

select (1 ^ AUTOINC_SEED) as IDENT from information_schema.columns

这篇关于SQL CE 选择语句中的反转布尔(位)值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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