Home > DeveloperSection > Forums > Having trouble setting a computed column as not Null
Ankit Singh

Total Post:341

Points:2389
Posted on    May-04-2013 2:01 AM

 MSSQL Server MSSQL Server 
Ratings:


 1 Reply(s)
 677  View(s)
Rate this:
Hi All!

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)

Thanks in advance! 


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    May-04-2013 8:55 AM

Hi Ankit!

You can try as following query

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


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

Follow MindStick