Search code examples
sql-server-2005insertion

Require help in Inserting records from one table to another table in Sql server 2005


I have two tables. One is temp table and another is main table. In temp table, I have a column called "Contract Number" which is of "float" datatype. In Main table, I have a same column "Contract Number" but with "varchar(50)" datatype.

In Temp table, the Contract Number column has a value "40494318". When I insert into the Main table the value changes into "4.04943e+007".

I used the query,

INSERT INTO Temp_Contract (Contract_Num)  
Select Contract_Num From Main_Contract

Please help me how to insert the values correctly.


Solution

  • If you're sure Contract_Num is always an integer:

    INSERT INTO Temp_Contract
        (Contract_Num)
        SELECT CAST(Contract_Num AS INT)
            FROM Main_Contract