user1452705
user1452705

Reputation:

Pass Null value for Date SQL Server

I am trying to pass a Null value for Data in SQL Server, but I keep getting a value of '1900-01-01'

strSQL = "INSERT INTO Table (Data_Col) VALUES ('Null')"

How do I get a Null value instead of this value '1900-01-01'?

Edit: This gives an error

strSQL = "INSERT INTO Ex_Tbl (Data_1, Data_2, Date_1, Date_2, Data_3)
            VALUES (1,2,'2015-3-2',,30)"

But this does not

strSQL = "INSERT INTO Ex_Tbl (Data_1, Data_2, Date_1, Date_2, Data_3)
           VALUES (1,2,'2015-3-2','',30)"

Edit No.2 Do I need to make the string look like this.

strSQL = "INSERT INTO Ex_Tbl (Data_1, Data_2, Date_1, Date_2, Data_3)
           VALUES (1,2,'2015-3-2',Null,30)"

If so, I am going to need code like this correct,

strSQL = "INSERT INTO Ex_Tbl (Data_1, Data_2, Date_1, Date_2, Data_3) 
           VALUES (1,2,'2015-3-2'," & "Null" & ",30)"

Upvotes: 1

Views: 643

Answers (1)

Matt
Matt

Reputation: 2869

Try strSQL = "INSERT INTO Table (Data_Col) VALUES (NULL)"

Null in quotes counts a string = Invalid date format = changes to 1900-01-01.

Upvotes: 5

Related Questions