无法将计算列设置为非空 [英] Having trouble setting a computed column as not Null

查看:101
本文介绍了无法将计算列设置为非空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题将计算列设置为 not null



我想要实现的是 C001 C002 ... 等,同时将其设置为 not null



我在论坛上阅读过,通过对NULL值使用默认值0可以实现。

Eg, ISNULL(Price + Taxes,0)



我已尝试申请此公式:

 ('C'+ right('000'+ CONVERT([varchar](3),[ID],(0)), $ b  

但它似乎不工作。任何人都可以告诉我我失踪了什么?

  ALTER CreditCard帐户不是ISNULL('C'+ right('000'+ CONVERT ([varchar](3),[idCreditCard],(0)),(3)),0)


解决方案

我终于找到了我的问题的解决方案!



正确的查询应为:

  ALTER TABLE CreditCard ADD accountNo AS ISNULL('C'+ right('000'+ CONVERT([varchar](3),[idCreditCard],(0)),(3)),0)
/ pre>

感谢帮助家伙!


I'm having problems setting a computed column as not null.

What I want to achieve is C001,C002..., etc. and at the same time set it as not null.

I have read on a forum that this can be achieved by using the default value 0 for NULL values.
E.g., ISNULL(Price + Taxes, 0)

I have tried to apply to this formula:

('C'+right('000'+CONVERT([varchar](3),[ID],(0)),(3)))

But it didn't seem to work. Can anyone tell me what am I missing?

ALTER CreditCard accountNo AS ISNULL('C'+right('000'+CONVERT([varchar](3),[idCreditCard],(0)),(3)),0)

解决方案

I've finally found the solution to my problem!

The correct query should be:

ALTER TABLE CreditCard ADD accountNo AS ISNULL('C'+right('000'+CONVERT([varchar](3),[idCreditCard],(0)),(3)),0)

Thanks for the help guys!

这篇关于无法将计算列设置为非空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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