error in merging the data from 2 tables

  • Hello All,

    I have to merge the data in 2 tables, all the columns and datatypes are same for both tables, I have date column as one column in both tables and I dont want to modify the data, I am just trying to append the data into one table. I am getting an error message:

    Msg 273, Level 16, State 1, Line 1

    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.

    Please suggest me what to do.

    Thanks you all for your valuable suggestions

    Regards

  • Timestamp is a rowversion. This is kept 100% by the server. You can select it but you can't insert / update it.

    Just leave that column out of the insert / select list.

    If for some reason you need a to keep that value then you need to cast to BINARY(8).

  • Thank you all

    I got the solution, I just changed the datatype of that column to nvarchar and do the insert operation and again change the datatype to datatime. below is the sample query that I used

    to change the datatype:

    Alter table <your table name>

    alter columns <your column name> varchar(30) not null (or u may define null)

    to do the insert operation (if u already created the destination table):

    insert into destination table( col_1, col_2)

    select col_1, col_2 from source table

    To change the datatype back to datetime:

    Alter table <your table name>

    alter columns <your column name> datetime not null (or u may define null)

    Regards

  • timestamp is NOT a datetime. Yes, bad choice for type name.

    timestamp is a binary that can be converted to date but it has no date meaning... you just lost 1 column of data (not harm done tho). Just change it back to timestamp and all comes back to what it was.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply