Home > DeveloperSection > Forums > Having trouble setting a computed column as not Null
Simons Hood
Simons Hood

Total Post:70

Posted on    April-17-2013 2:25 AM

 MSSQL Server MSSQL Server 

 1 Reply(s)
 1522  View(s)
Rate this:
Hi Everyone!

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:

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)

Advance thanks! 


Total Post:604

Posted on    April-17-2013 9:21 AM

Hi Samuel!

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!

Don't want to miss updates? Please click the below button!

Follow MindStick