2

I'm attempting to insert a datetime('2013-08-30 19:05:00') value into a SQL server database table column(smalldatetime) and the value stays "NULL" after the insert.

I'm doing this to 6 other columns that are the exact same type. What is this only occuring on one column? I've triple checked that the names of the columns are correct. Any ideas?

4
  • Did you try to make the sql column be timestamp timestamp default current_timestamp? Anyway your question is not specific enough, post the code, show us what's failing. Commented Aug 30, 2013 at 21:11
  • 3
    First idea would be to post your code, and give more details about the table. Commented Aug 30, 2013 at 21:12
  • 3
    Also check for triggers on the table. Commented Aug 30, 2013 at 21:13
  • @Martin - You were correct in saying to check the triggers,it was missing the new date column. Thanks! Commented Aug 30, 2013 at 21:25

1 Answer 1

7

Assuming the situation is as you describe

CREATE TABLE T
(
S SMALLDATETIME NULL
)

INSERT INTO T 
VALUES('2013-08-30 19:05:00')

SELECT *
FROM T /*Returns NULL*/

There are only two ways I can think of that this can happen.

1) That is an ambiguous datetime format. Under the wrong session options this won't cast correctly and if you have some additional options OFF it will return NULL rather than raise an error (e.g.)

SET LANGUAGE Italian;
SET ansi_warnings OFF;
SET arithabort OFF; 

INSERT INTO T 
VALUES('2013-08-30 19:05:00')

SELECT *
FROM T /*NULL inserted*/

2) You may have missed the column out in an INSTEAD OF trigger, or have an AFTER trigger that actually sets the value back to NULL.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.