返回另一列是否为空的计算位列
我尝试使用这个计算列:
CREATE TABLE dbo.Item
(
ItemId int NOT NULL IDENTITY (1, 1),
SpecialItemId int NULL,
--I tried this
IsSpecialItem AS ISNULL(SpecialItemId, 0) > 0,
--I tried this
IsSpecialItem AS SpecialItemId IS NOT NULL
--Both don't work
) ON [PRIMARY]
I try to have this computed column:
CREATE TABLE dbo.Item
(
ItemId int NOT NULL IDENTITY (1, 1),
SpecialItemId int NULL,
--I tried this
IsSpecialItem AS ISNULL(SpecialItemId, 0) > 0,
--I tried this
IsSpecialItem AS SpecialItemId IS NOT NULL
--Both don't work
) ON [PRIMARY]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这有效:
This works:
Mark Byer 的回答 导致
nvarchar
列出现错误,无论列是否为 <代码>int或nvarchar
:Mark Byer's answer causes an error with
nvarchar
columns, the following works regardless of whether column isint
ornvarchar
:SQL Server 没有任何本机 true 布尔数据类型(从某种意义上说,您可以使用变量代替布尔表达式,例如
select * from Item where IsSpecialItem
)。表示它的唯一方法是像 Mark 建议的那样,使用保留值(在这种情况下,您的查询将是select * from Item where IsSpecialItem = 1
)。SQL Server doesn't have any native true boolean data type (in the sense that you could use a variable in place of a boolean expression, like
select * from Item where IsSpecialItem
). The only way you can represent it is with something like Mark suggests, using reserved values (in this case, your query would beselect * from Item where IsSpecialItem = 1
).