Default column to Null value

I want to Default my addnum column = null Where parcel.address_ID is null. Both in the same table.

In the Default Value or Binding Column properties i added this but its not working.  ('Set addnum = null Where parcel.address_ID is null')

I would like my addnum column to be populated with a Address Vale or be null.
Addnum column is nvarchar(10)
Address_ID colunm is INT

Thanks
PtboGiserAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Jesus RodriguezConnect With a Mentor IT ManagerCommented:
Must be something like this

USE Your_Database
GO
IF OBJECT_ID ('Parcel.CheckParcelAddress', 'TR') IS NOT NULL
   DROP TRIGGER Parcel.CheckParcelAddress;
GO
CREATE TRIGGER CheckParcelAddress
ON Your_Database.Parcel
AFTER INSERT, UPDATE
AS
  UPDATE Parcel
  SET ADDNUM=NULL
  WHERE ADDRESS_ID IS NULL
GO
0
 
Jesus RodriguezIT ManagerCommented:
You need to use a trigger on Insert.
Just check to see if a value has been assigned, and if not, go grab the correct one and use it
0
 
PtboGiserAuthor Commented:
Thx i'll try it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.