Solved

Default column to Null value

Posted on 2013-06-14
3
570 Views
Last Modified: 2013-06-14
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
0
Comment
Question by:PtboGiser
  • 2
3 Comments
 
LVL 13

Expert Comment

by:Jesus Rodriguez
ID: 39248257
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
 
LVL 13

Accepted Solution

by:
Jesus Rodriguez earned 500 total points
ID: 39248291
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
 

Author Comment

by:PtboGiser
ID: 39248613
Thx i'll try it.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now