Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timestamp error

Status
Not open for further replies.

TarunMakhija

Programmer
Jun 14, 2005
13
US
Hi,

The first column in my table is of type Timestamp

I am trying to execute queries of the form:

insert into News values(2005-12-26 08:43:00.0,'UN','topnews')

Error: Incorrect syntax near '08'.

insert into News values(2005-12-26 09:43:00.0,'UN','topnews')

Incorrect syntax near '09'.

Can someone tell me exactly what is going wrong here?

Thanks a lot.
Tarun M.
 
Timestamp is not the same thing as Date/Time. There is a timestamp field in SQL Server, a DateTime field, and a SmallDateTime field.

If you want to store a DateTime value, then you should change your data type. Even so, the syntax you have is wrong (but close).

When inserting records in to a table, you do not have to specify the fields you are inserting, but you should. You should ALWAYS do this, anything else is 'sloppy' programming, in my opinion.

The generic format for inserts....

Insert into table(Field1, field2, field3)
Values(val1,val2,val3)

When the data types for your fields are: char, nchar, varchar, nvarchar, text, ntext, datetime, or SmallDateTime THEN you must enclose the data with apostrophes.

Insert into News(DateField, field1,field2)
Values ('2005-12-27 14:35:00','UN','topnews')

Hope this helps.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top