Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Nullable Column

I have a SQL Server table with a few columns of type varchar which are nullable. When an aspx page posts data if the textbox is empty, the database table column is updated to an empty string.

To maintain the null value rather han have it replaced by an empty string, I can either have the logic to change the empty string to System.DBnull in the middle tier c# code or do so in the stored procedure.

Are there other better ways to handle this situation?

like image 810
klork Avatar asked Mar 10 '26 12:03

klork


1 Answers

you can use a trigger or do it in the proc, you can use the NULLIF function

Example

DECLARE @d VARCHAR(20)
SELECT @d = ''
SELECT NULLIF(@d,'')
like image 156
SQLMenace Avatar answered Mar 13 '26 16:03

SQLMenace