sql server programming:
Hi, I just found out on my 2000, when I do a bulk insert, if I create the table with field type of nvarchar, it always fail with error Server: Msg 4863, Level 16, State 1, Line 1 Bulk insert data conversion error (truncation), but if I change the type to varchar, bulk insert works perfectly fine. Any ideas what is the reason? Thanks Hao
(huohaodian@gmail.com) writes: [quoted text, click to view] > I just found out on my 2000, when I do a bulk insert, if I create the > table with field type of nvarchar, it always fail with error Server: > Msg 4863, Level 16, State 1, Line 1 Bulk insert data conversion error > (truncation), but if I change the type to varchar, bulk insert works > perfectly fine. Any ideas what is the reason?
As long as varchar/nvarchar is the sole difference it should matter. I think you need to provide as with more information of what you are doing. It would help if you posted: 1) The definition of your table. 2) The BULK INSERT command you are using. 3) Any format file that you use. 4) A sample data file. Preferrably add the file as an attachment, or put it on a web site and post a link to it. -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at
Hi Hao, NVarchar uses twice the space for every charecter you enter. Check the size of your data? If its more than 4000 charecters than NVarchar will fail. -- Thank you, Saleem Hakani HTTP://WWW.SQLCOMMUNITY.COM (World Wide SQL Server Community) SQLTips, SQL Forums, SQL Blogs, SQL RADIO, SQL Events, SQL Scripts, SQL Articles, SQL Clinic and a lot of SQL fun. [quoted text, click to view] "huohaodian@gmail.com" wrote: > Hi, > > I just found out on my 2000, when I do a bulk insert, if I create the > table with field type of nvarchar, it always fail with error Server: > Msg 4863, Level 16, State 1, Line 1 Bulk insert data conversion error > (truncation), but if I change the type to varchar, bulk insert works > perfectly fine. Any ideas what is the reason? > > Thanks > > Hao >
I have used follows create table User ( UserID varchar(11), UserName varchar(32) ) go bulk insert User from 'C:\Project\User.txt' with (formatfile = 'C: \Project\User.fmt') go format file is something like follow 8.0 3 1 SQLCHAR 0 11 "" 1 UserD SQL_Latin1_General_CP1_CI_AS 2 SQLCHAR 0 32 "" 2 UserName SQL_Latin1_General_CP1_CI_AS 3 SQLCHAR 0 115 "\n" 0 Unused SQL_Latin1_General_CP1_CI_AS [quoted text, click to view] On Oct 14, 6:16 am, Erland Sommarskog <esq...@sommarskog.se> wrote: > (huohaod...@gmail.com) writes: > > I just found out on my 2000, when I do a bulk insert, if I create the > > table with field type of nvarchar, it always fail with error Server: > > Msg 4863, Level 16, State 1, Line 1 Bulk insert data conversion error > > (truncation), but if I change the type to varchar, bulk insert works > > perfectly fine. Any ideas what is the reason? > > As long as varchar/nvarchar is the sole difference it should matter. I think > you need to provide as with more information of what you are doing. It > would help if you posted: > > 1) The definition of your table. > 2) The BULK INSERT command you are using. > 3) Any format file that you use. > 4) A sample data file. Preferrably add the file as an attachment, or put > it on a web site and post a link to it. > > -- > Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se > > Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books... > Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
[quoted text, click to view] On Oct 14, 6:32 pm, Erland Sommarskog <esq...@sommarskog.se> wrote: > (huohaod...@gmail.com) writes: > > I have used follows > > > create table User ( > > UserID varchar(11), > > UserName varchar(32) > > ) > > go > > > bulk insert User from 'C:\Project\User.txt' with (formatfile = 'C: > > \Project\User.fmt') > > go > > > format file is something like follow > > > 8.0 > > 3 > > 1 SQLCHAR 0 11 "" 1 > > UserD SQL_Latin1_General_CP1_CI_AS > > 2 SQLCHAR 0 32 "" 2 UserName > > SQL_Latin1_General_CP1_CI_AS > > 3 SQLCHAR 0 115 "\n" 0 Unused > > SQL_Latin1_General_CP1_CI_AS > > And where did you put the sample data file? > > And I will have to admit that I don't really like "format file is something > like follows". Please make sure that the information you post here, > reproduces the issue you see. Yes, I am asking you do some work, but > you are the one who is asking for help, and I don't really feel like > trying at random to see what might be happening to you. > > -- > Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se > > Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books... > Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx Thanks a lot for your time and helps. I was trying to figure out how to attach the file for this thread, but no luck, now I could only post the one line of source data here, 103364Cote,AER E 00002700002516 50 DDD EEE NO RESTRICT 189894TH FLR CCH A 2.00 2.00 0.30ABC xx.xxPTO 122.8 48.0EIB 80.0 0.0CLB 3.3 3.3 Thanks again
[quoted text, click to view] On Oct 14, 6:32 pm, Erland Sommarskog <esq...@sommarskog.se> wrote: > (huohaod...@gmail.com) writes: > > I have used follows > > > create table User ( > > UserID varchar(11), > > UserName varchar(32) > > ) > > go > > > bulk insert User from 'C:\Project\User.txt' with (formatfile = 'C: > > \Project\User.fmt') > > go > > > format file is something like follow > > > 8.0 > > 3 > > 1 SQLCHAR 0 11 "" 1 > > UserD SQL_Latin1_General_CP1_CI_AS > > 2 SQLCHAR 0 32 "" 2 UserName > > SQL_Latin1_General_CP1_CI_AS > > 3 SQLCHAR 0 115 "\n" 0 Unused > > SQL_Latin1_General_CP1_CI_AS > > And where did you put the sample data file? > > And I will have to admit that I don't really like "format file is something > like follows". Please make sure that the information you post here, > reproduces the issue you see. Yes, I am asking you do some work, but > you are the one who is asking for help, and I don't really feel like > trying at random to see what might be happening to you. > > -- > Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se > > Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books... > Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx Here is the format file: 8.0 3 1 SQLCHAR 0 11 "" 1 UserD SQL_Latin1_General_CP1_CI_AS 2 SQLCHAR 0 32 "" 2 UserName SQL_Latin1_General_CP1_CI_AS 3 SQLCHAR 0 115 "\n" 0 Unused SQL_Latin1_General_CP1_CI_AS
(huohaodian@gmail.com) writes: [quoted text, click to view] > I have used follows > > create table User ( > UserID varchar(11), > UserName varchar(32) > ) > go > > bulk insert User from 'C:\Project\User.txt' with (formatfile = 'C: > \Project\User.fmt') > go > > format file is something like follow > > 8.0 > 3 > 1 SQLCHAR 0 11 "" 1 > UserD SQL_Latin1_General_CP1_CI_AS > 2 SQLCHAR 0 32 "" 2 UserName > SQL_Latin1_General_CP1_CI_AS > 3 SQLCHAR 0 115 "\n" 0 Unused > SQL_Latin1_General_CP1_CI_AS
And where did you put the sample data file? And I will have to admit that I don't really like "format file is something like follows". Please make sure that the information you post here, reproduces the issue you see. Yes, I am asking you do some work, but you are the one who is asking for help, and I don't really feel like trying at random to see what might be happening to you. -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at
See this one create table dbo.tb(c1 nvarchar(30),c2 nvarchar(30), c3 nvarchar(30)) go /* "P","ISSUE","Misc Material Issue" "P","MOVE","Misc Material Move" "J","POST","Misc Post Material" "J","MOVE","Misc Material Move" 8.0 3 1 SQLCHAR 0 30 "\",\"" 1 c1 "" 2 SQLCHAR 0 30 "\",\"" 2 c2 "" 3 SQLCHAR 0 30 "\r\n" 3 c3 "" */ bulk insert dbo.tb from 'c:\temp\txt.txt' with (formatfile='c:\temp\fmt.fmt') go select * from dbo.tb go drop table dbo.tb [quoted text, click to view] <huohaodian@gmail.com> wrote in message news:1192412734.555669.326230@e34g2000pro.googlegroups.com... > On Oct 14, 6:32 pm, Erland Sommarskog <esq...@sommarskog.se> wrote: >> (huohaod...@gmail.com) writes: >> > I have used follows >> >> > create table User ( >> > UserID varchar(11), >> > UserName varchar(32) >> > ) >> > go >> >> > bulk insert User from 'C:\Project\User.txt' with (formatfile = 'C: >> > \Project\User.fmt') >> > go >> >> > format file is something like follow >> >> > 8.0 >> > 3 >> > 1 SQLCHAR 0 11 "" 1 >> > UserD SQL_Latin1_General_CP1_CI_AS >> > 2 SQLCHAR 0 32 "" 2 UserName >> > SQL_Latin1_General_CP1_CI_AS >> > 3 SQLCHAR 0 115 "\n" 0 Unused >> > SQL_Latin1_General_CP1_CI_AS >> >> And where did you put the sample data file? >> >> And I will have to admit that I don't really like "format file is >> something >> like follows". Please make sure that the information you post here, >> reproduces the issue you see. Yes, I am asking you do some work, but >> you are the one who is asking for help, and I don't really feel like >> trying at random to see what might be happening to you. >> >> -- >> Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se >> >> Books Online for SQL Server 2005 >> at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books... >> Books Online for SQL Server 2000 >> at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx > > Here is the format file: > > 8.0 > 3 > 1 SQLCHAR 0 11 "" 1 UserD SQL_Latin1_General_CP1_CI_AS > 2 SQLCHAR 0 32 "" 2 UserName SQL_Latin1_General_CP1_CI_AS > 3 SQLCHAR 0 115 "\n" 0 Unused SQL_Latin1_General_CP1_CI_AS >
(huohaodian@gmail.com) writes: [quoted text, click to view] > Thanks a lot for your time and helps. I was trying to figure out how > to attach the file for this thread, but no luck, now I could only post > the one line of source data here, > 103364Cote,AER E 00002700002516 50 DDD > EEE NO RESTRICT 189894TH FLR CCH A 2.00 > 2.00 0.30ABC xx.xxPTO 122.8 > 48.0EIB 80.0 0.0CLB > 3.3 3.3
So put the file on a web site and post a link to it. When BCP uses a format file, it handles the file as binary, so any tweak it with CR-LF etc matters. And, please, post an entire scenario where you get the error, and where you actually have verified that the issue occurs. If you are not prepared to make that effort, at least I will not be prepared to make the effort to understand what is going on. -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at
Don't see what you're looking for? Try a search.
|