Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have task where i need to move data from one table1 to table2, i have source columns and destination columns but before i move data is it possible to find out is there any data in source column doesn't not fit destination column because of destination field type difference or field length is less like that ?

Like in a scenario i have source column which is char(1) and i am trying to map that column data to int column, here most of rows in source column have integer values but there are some alpha characters in some rows so i want to find out all those rows which are going to fail....the logic should work for all data types.

Thanks in advance!!
Posted

1 solution

Have a look here: On Error Resume Next SQL Server 2005[^]

But you should know that there is no something like "the golden rule" for this kind of functionality. There is only one person who can write it: YOU! So, write validation rules depending on your needs.

Here is an idea for CHAR(1) to INT conversion:
SQL
SELECT CONVERT(INT, AkaIntField) AS NewInt
FROM (
    SELECT AkaIntField
    FROM TableName
    WHERE ISNUMERIC(AkaIntField)=1
) AS T
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900