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
mmalik15Asked:
Who is Participating?
 
Aaron TomoskySD-WAN SimplifiedCommented:
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.
0
 
Kevin CrossChief Technology OfficerCommented:
Do you have data over 4000 characters? One simple approach would be to CONVERT(VARCHAR(4000), Question) in export query.
0
 
Aaron TomoskySD-WAN SimplifiedCommented:
You can output as csv and then open that in excel
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
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.
0
 
Aaron TomoskySD-WAN SimplifiedCommented:
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)
0
 
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.
0
 
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?
0
 
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?
0
 
Aaron TomoskySD-WAN SimplifiedCommented:
Change the table name, put in the columns instead of *
yep.
0
 
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?
0
 
Kevin CrossChief Technology OfficerCommented:
Correct. If you have the ability to put these in the same instance and have for example.

ProductDB.dbo.TableName
RestoredDB1.dbo.TableName
RestoredDB2.dbo.TableName
RestoredDB3.dbo.TableName

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
WHERE NOT EXISTS (
   SELECT 1
   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}
)
SELECT *
FROM cte
WHERE RN > 1
;

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!
0
 
Aaron TomoskySD-WAN SimplifiedCommented:
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
0
 
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.
0
 
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.
0
 
Aaron TomoskySD-WAN SimplifiedCommented:
If I had a keyboard I'd have awesome descriptive solutions of awsomeness too ;)
0
 
mmalik15Author Commented:
Brilliant comments guy!

Many thanks
0
 
Kevin CrossChief Technology OfficerCommented:
Aaron,

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,

Kevin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.