Could not export sql server 2008 table's varchar (8000) column to excel 2007

while trying to export a table with varchar column(8000) to excel 2007 or 2003 i m getting the following error. The mappings show the varchar(8000) is trying to convert in long text

Could not connect destination component.

Error 0xc0204016: SSIS.Pipeline: The "output column "Question" (71)" has a length that is not valid. The length must be between 0 and 4000.

any ideas how can we fix this
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kevin CrossChief Technology OfficerCommented:
Do you have data over 4000 characters? One simple approach would be to CONVERT(VARCHAR(4000), Question) in export query.
Aaron TomoskyDirector of Solutions ConsultingCommented:
You can output as csv and then open that in excel
Kevin CrossChief Technology OfficerCommented:
The other option, as I believe it is type conversion issue, is to convert to NVARCHAR(MAX) or NVARCHAR(8000). Aaron's suggestion looks promising also as the conversion issue is between providers, so it may just be a conflict with the Excel provider that can be overcome by going to CSV.
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

Aaron TomoskyDirector of Solutions ConsultingCommented:
You could also cast as text instead of varchar 4000, that way you don't lose anything.

Another thought, I've had excel be unhappy with varchar(max) even though it should be the same as varchar(8000). If it is set to varchar(max) try cast as varchar(8000)
Kevin CrossChief Technology OfficerCommented:
Nice suggestions, aarontomosky. I would NOT go with a cast to TEXT, though. It is being deprecated and really should be used in SQL 2008 if can be avoided.
mmalik15Author Commented:
Thanks for the comments guys. I have tried exporting in csv and it exports okay. The root problem that I have is that  I have three versions of the same database. Three different people have inserted data into the same table and i need to synchronise that table now from those databases. I thought it would be easier to export in excel and use excel filter to remove duplicates and import into database again. This import/export between MS Sql server 2008 and excel 2007 is not looking very friend and i wonder if there is a better solution to acheive the desired result.

p.s. shall I put this as seperate question as the context of the problem is different now?
Aaron TomoskyDirector of Solutions ConsultingCommented:
If you can get all three db on the same server (or do some trickery to cross server query) you can do it all right from ssms. Basically From the db with new data:
 insert into dbname.dbo.table select * from table where pk not in (select pk from dbname.dbo.table)

Repeat from other DBs.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mmalik15Author Commented:
As the db name is same for all the three dbs so jus rename the db's attach them all to the same instance of sql server and use insert into dbname.dbo.table select * from table where pk not in (select pk from dbname.dbo.table)

is that right?
Aaron TomoskyDirector of Solutions ConsultingCommented:
Change the table name, put in the columns instead of *
mmalik15Author Commented:
thanks again for the comments. One final issue the pk is auto genrated and could be same in different databases. Guess we should be able to filter on varchar fieids too?
Kevin CrossChief Technology OfficerCommented:
Correct. If you have the ability to put these in the same instance and have for example.


Then it is pretty straight forward. I would use NOT EXISTS personally.

INSERT INTO ProductDB.dbo.TableName({column list})
SELECT {column list}
FROM RestoredDB1.dbo.TableName r
   FROM ProductDB.dbo.TableName p
   WHERE p.pkColumn = r.pkColumn

Other notes, if these are on different databases and pkColumn is sequential, you may need to account for the fact that pkColumn may exist but reflect different data. Therefore, is there other data that identifies a row as a unique entry? If so, take advantage of that. In addition, you will need to determine which database wins in conflict resolution.

Similarly, within a table if there are duplicates, you can use ROW_NUMBER() and CTE to eliminate the duplicates like:

;WITH cte AS (
   SELECT *, ROW_NUMBER() OVER(PARTITION BY {columns that make unique row} ORDER BY pkColumn) RN
   FROM {any table}
FROM cte

Change this to a DELETE and it will remove all the extra rows, leaving the one you want to keep, i.e., RN = 1. ORDER BY should be how you want these. You may choose to take last updated for example (e.g., ORDER BY LastModifiedDate DESC).

Hope that helps!
Aaron TomoskyDirector of Solutions ConsultingCommented:
Does the table have one unique field across the databases? Maybe you do want to make this a separate question with more detail on the table
Kevin CrossChief Technology OfficerCommented:
Sorry, I was typing and missed the other posts in the thread. Hopefully, my comment answers some of your questions. Apologies for duplication already handled in previous couple of posts from aaron.
Kevin CrossChief Technology OfficerCommented:
Agree. I think http:#36900730 should be pretty detailed to get you on the way, coupled with aaron's advice to this point; therefore, I would give it a try and then if you have specific errors or challenges post a new question. For now, it appears http:#36900535 answers the original question.
Aaron TomoskyDirector of Solutions ConsultingCommented:
If I had a keyboard I'd have awesome descriptive solutions of awsomeness too ;)
mmalik15Author Commented:
Brilliant comments guy!

Many thanks
Kevin CrossChief Technology OfficerCommented:

You made some pretty "awesome descriptive solutions of awesomeness" without a keyboard. It was a pleasure collaborating with you BOTH.

mmalik15, glad we could help!

Best regards and happy coding,

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.