Link to home
Start Free TrialLog in
Avatar of homnath_sharma
homnath_sharma

asked on

converting timestamp to datetime

I have collumn data with timestamp value, and when i try to insert into datetime column, its throwing error as:

Msg 260, Level 16, State 1, Server SYS_034, Procedure TD_History, Line 17
Disallowed implicit conversion from data type datetime to data type timestamp, table 'MASTER.dbo.AUD_History', column 'DateRealisation'. Use the CONVERT function to run this query.

hOPE you will have immed solution.

Thanks in adv..
~ HNS ~
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of homnath_sharma
homnath_sharma

ASKER

Aneesh,

I need to insert datetime column data of one table into  timestamp column field in another table.

Regds.
~ HNS ~
You dont have to specify the value in the Timestamp column explicitly, it will be inserted/modified automatically with the insert/update operation

See,

I am trying to insert value at runtime thru trigger as below:

create trigger hist
on DBO.XXX_History
instead of delete
as
begin
INSERT INTO DBO.AUD_History SELECT d.DateRealisation from deleted d.
end

AUD_History.DateRealisation is of type (timestamp)
XXX_History.DateRealisation is of type (datetime)

Error is as:
Disallowed implicit conversion from data type datetime to data type timestamp, table 'Expert.dbo.AUD_History', column 'DateRealisation'. Use the CONVERT function to run this query.


Regd.s
~ HNS ~
can you post the table structure
I think you're going to have to change your data structure to change the data type of that field or add an additional field. From SQL Books Online:

"The SQL Server timestamp data type has nothing to do with times or dates. SQL Server timestamps are binary numbers that indicate the relative sequence in which data modifications took place in a database. The timestamp data type was originally implemented to support the SQL Server recovery algorithms."

"Never use timestamp columns in keys, especially primary keys, because the timestamp value changes every time the row is modified."

Why is AUD_History.DateRealisation of type timestamp?
Thanks for Grace "C"
Hope you need to go thru the User terms and conditions
https://www.experts-exchange.com/help.jsp#hi73
https://www.experts-exchange.com/help.jsp#hi18