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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.