Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Timestamp errot

Author  Topic 

TarunMakhija
Starting Member

2 Posts

Posted - 2005-12-27 : 20:31:45
Hi,

The first column in my table is of type Timestamp

I am trying to execute queries of the form:
-------------------------------------------------
Query: insert into News values(2005-12-26 08:43:00.0,'UN','topnews')

Error: Incorrect syntax near '08'.
-------------------------------------------------
Query: insert into News values(2005-12-26 09:43:00.0,'UN','topnews')

Error: Incorrect syntax near '09'.
-------------------------------------------------
Can someone tell me exactly what is going wrong here?

Thanks a lot.
Tarun M.

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2005-12-27 : 20:45:34
Put the datetime inside single quotes & try as in
insert into News values('2005-12-26 09:43:00.0','UN','topnews')

if the above is not working, try
insert into News values(getdate(),'UN','topnews')

Also the timestamp is datatype with default values (as auto increment type), so try without data for that field as
insert into News(field1,field2)values('UN','topnews') -- timestamp type field is ommited in fields & data lists

Go to Top of Page

TarunMakhija
Starting Member

2 Posts

Posted - 2005-12-28 : 00:07:21
Hi Srinika,

Thanks for the reply. I had tried with the quotes as well before sending the mail. It does not work.

About the getDate() method, actually the timestamp i am using is not the current data/time. It is a string that i have parsed and converted to java.util.date followed by converting it to long and then finally java.sql.Timestamp. So the getDate() doesnt solve the problem as well ...

Any other suggestions?

Thanks a lot!
Tarun
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-28 : 01:03:15
Are you referring the TimeStamp datatype of SQL Server? If so you need to omit it when inserting the value and SQL Server will generate unique value for each row


Declare @t table(t timestamp,code varchar(1))
insert into @t(code) select 'a'
select * from @t

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

yonabout
Posting Yak Master

112 Posts

Posted - 2005-12-28 : 07:10:51
I'm not sure why you're using timestamp in your table, it looks like the datetime datatype would be better for you, and your initial insert into statement would work (with quotes around the date string).

timestamp datatypes are updated automatically every time you alter the row anyway, so if you're trying to use it as a key, any update to the row will mean your key has changed.


Cheers,

Yonabout
Go to Top of Page
   

- Advertisement -