Skip to main content
Participant
March 7, 2009
Question

setting timestamp

  • March 7, 2009
  • 2 replies
  • 1445 views
Hi
In my MSSQL server I have a table column called timestamp of type timestamp.
In my Coldfusion file, I set a parameter called 'timestamp' = Now(), and cfsqltype="CF_SQL_TIMESTAMP" . However, when I tried a database query to insert 'timestamp' into SQL, it resulted in the following error msg:

[Macromedia][SQLServer JDBC Driver][SQLServer]Cannot insert an explicit value into a timestamp column. Use INSERT with a column list to exclude the timestamp column, or insert a DEFAULT into the timestamp column.

Should I be doing something differently? I tried setting type to string etc but nothing is working for me and I have spent hours on this.
Thanks
This topic has been closed for replies.

2 replies

Inspiring
March 7, 2009
> [Macromedia][SQLServer JDBC Driver][SQLServer]Cannot insert an explicit value
> into a timestamp column. Use INSERT with a column list to exclude the timestamp
> column, or insert a DEFAULT into the timestamp column.
>
> Should I be doing something differently? I tried setting type to string etc
> but nothing is working for me and I have spent hours on this.
> Thanks

The error message is very clear as to what the problem is and what the
solution is.

Timestamp columns can't take values in an insert statement, the DB
populates them automatically.

I found this out by googling your error message, and the very first match
explains it.

http://tinyurl.com/d8blyc
< http://www.google.com/search?hl=en&safe=off&q=Cannot+insert+an+explicit+value+into+a+timestamp+column.+Use+INSERT+with+a+column+list+to+exclude+the+timestamp+column%2C+or+insert+a+DEFAULT+into+the+timestamp+column.+&btnG=Search>

As does the second match, now that I look at it.

A good rule of thumb is that the first thing you should do if you get
stumped by an error (if just reading the error message doesn't explain it
;-), is to google the error message. I find that generally the answers
within the first two pages of results, quite often the first result!


--
Adam
Inspiring
March 7, 2009
There was a recent thread on this topic. The problem could be that an MS Sql timestamp field might not be what you think it is. A better datatype choice would be date, which has a time component.

Also, for the current date and time, you could use ms sql's getdate() function.