I have data in a table that has a large number of columns, many of them nvarchar of varying widths. Im trying to take that data and insert it into another table but Im getting the warning message about string or binary data being truncated. I suspect there is a field somewhere that is not large enough for the data. However, I run across this often enough I would like to come up with a better solution than just eyeballing the data.
I found this example
http://www.sqlservercentral.com/Forums/Topic1115499-338-2.aspx
(credit goes to poster in the linked thread above)
Select columns into #T from MyDataSource; select * from tempdb.sys.columns as TempCols full outer join MyDb.sys.columns as RealCols on TempCols.name = RealCols.name and TempCols.object_id = Object_ID(N'tempdb..#T') and RealCols.object_id = Object_ID(N'MyDb.dbo.MyTable) where TempCols.name is null -- no match for real target name or RealCols.name is null -- no match for temp target name or RealCols.system_type_id != TempCols.system_type_id or RealCols.max_length < TempCols.max_length ;
Why a full outer join ? Why not just a left join, since I really only want to see the matches on my source table?
When Im running this against the table im interested in, it doesnt seem to find matches between my target table and my temp table