0

I'm trying to populate a temp table, and I'm getting this error
Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated.
The statement has been terminated.

Hmmmm ... here's what I'm trying.
I created two temp tables and populated #emails from a spreadsheet (text cvs)

CREATE TABLE #emails(
    email VARCHAR(40) PRIMARY KEY
)

CREATE TABLE #contacts(
    email VARCHAR(40) PRIMARY KEY,
    company VARCHAR(40),
    name VARCHAR(40),
    phone VARCHAR(40)
)

BULK INSERT #emails  
FROM 'E:DatabasesAndStorage\tempDBStorage\download.csv'  
WITH  
(  
    FIELDTERMINATOR = ',',  
    ROWTERMINATOR = '\n'  
)  
GO

Now I want to insert a bunch of records into #contacts from a query.
I started off testing my SELECT query by running it alone.

SELECT cont.primaryemailaddress AS email, cont.companyname AS company, cont.contactname AS name, cont.primaryphone AS phone
FROM companycontact AS cont, #emails
WHERE #emails.email = cont.primaryemailaddress

It runs great. 306 results, no errors.
But, when I try adding the INSERT part like this:

INSERT INTO #contacts (email, company, name, phone)
SELECT cont.primaryemailaddress AS email, cont.companyname AS company, cont.contactname AS name, cont.primaryphone AS phone
FROM companycontact AS cont, #emails
WHERE #emails.email = cont.primaryemailaddress

I get an error:
Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated.
The statement has been terminated.
error.

Any thoughts??
What am I missing??
~ Mo

1
Contributor
1
Reply
3
Views
6 Years
Discussion Span
Last Post by mOrloff
0

Ahhhh!
Nevermind.
I finally found it

My field lengths were too short.
Some of the data getting inserted was longer than the specified 40 chars.

Still, if anyone has any suggestions/critiques, I'd be happy to hear them and learn something new.
Thanks-a-bunch,
~ Mo

Edited by mOrloff: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.