---
title: "Having trouble setting a computed column as not Null"  
description: "Having trouble setting a computed column as not Null"  
author: "Anonymous User"  
published: 2013-04-17  
updated: 2013-04-17  
canonical: https://www.mindstick.com/forum/779/having-trouble-setting-a-computed-column-as-not-null  
category: "mssql server"  
tags: ["mssql server"]  
reading_time: 1 minute  

---

# Having trouble setting a computed column as not Null

Hi Everyone!\
I'm having problems setting a [computed column](https://www.mindstick.com/forum/808/having-trouble-setting-a-computed-column-as-not-null) as [not null](https://www.mindstick.com/interview/1933/what-is-not-null-constraint).\
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](https://www.mindstick.com/forum/2035/default-value-when-using-singleordefault) 0 for [NULL values](https://www.mindstick.com/interview/34072/optional-class-in-java-handling-null-values-more-effectively).E.g., ISNULL(Price + Taxes, 0)\
I have tried to apply to this [formula](https://answers.mindstick.com/qa/35906/is-formula-1-s-popularity-in-decline):\
('C'+right('000'+CONVERT([[varchar](https://www.mindstick.com/forum/161878/what-is-the-difference-between-nvarchar-and-varchar)](3),[ID],(0)),(3)))But it didn't seem to work. Can [anyone tell me](https://www.mindstick.com/interview/23033/can-anyone-tell-me-about-hadoop-toolbox) what am I missing?\
ALTER CreditCard accountNo AS ISNULL('C'+right('000'+CONVERT([varchar](3),[idCreditCard],(0)),(3)),0)\
[Advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams) thanks!

## Replies

### Reply by AVADHESH PATEL

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!


---

Original Source: https://www.mindstick.com/forum/779/having-trouble-setting-a-computed-column-as-not-null

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
