Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Set empty field value to NULL
Message
From
28/08/2016 19:25:22
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01640098
Message ID:
01640106
Views:
48
>>>>>Hi,
>>>>>
>>>>>Is it possible to change some property of a field/column in a SQL Database that automatically sets the value to NULL if the value is an empty string? That is, the application may update the value of a column to an empty string but I want the SQL to set it as NULL.
>>>>>
>>>>>TIA
>>>>
>>>>This can be done through a trigger. Simple AFTER UPDATE/INSERT trigger can do that.
>>>
>>>I will check out how to do it. Thanks.
>>
>>create trigger trMyTableMyColumnChange after insert, update
>>as
>>
>>update myTable set myColumn = null
>>from myTable inner join Inserted I on myTable.PK = Inserted.PK
>>where I.myColumn = ''
>
>Thank you!

Remember the old H&R Block TV commercials from the 1970's? "Reason #102 why H&R Block should do your taxes?"

My corollary for this - reason #102 why every database table should have a single column as a primary key definition.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform