Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 [solved] Truncating data when moving btwn tbls

Author  Topic 

ravl13
Starting Member

38 Posts

Posted - 2011-09-21 : 13:48:01
Greetings,

I am trying to move data from one table to another, but because truncation occurs, the following statement fails.

INSERT into PEBContacts (ID, firstname, lastname, address1, address2, address3, city, state, zip)
SELECT ID, firstname, lastname, address1, address2, address3, town, state, zip
FROM addresses


I realize this is "bad form" to truncate data and possibly lose data, but it does not matter in this case and I really want the data moved into the PEBContacts table. If any of these fields in the addresses table are over the varchar length of the columns in the PEBContacts table, it is screwy data anyway.

How can I force truncation while trying to move data from the addresses table to the PEBContacts table?

Or alternatively, what is a way to move data from one table to the other, using a method other than INSERT INTO and SELECT?

Thanks,
-ravl13

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-09-21 : 14:14:15
Use the LEFT function to grab the number of characters the data type supports in PEBContacts.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

ravl13
Starting Member

38 Posts

Posted - 2011-09-21 : 14:30:16
Ah, thanks. That worked fine!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-09-21 : 14:47:04
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -