Click to See Complete Forum and Search --> : Insert errors


gurupot
April 26th, 2007, 12:27 AM
Hi,

I have a basic insert statement like this,
INSERT INTO TRANS ( pin , date , time , type , amount , descr , userid ) VALUES ( '111111' , '20070425' , '230904' , '1Œ' , 3100 , '' , 'TEST' )

The table structure of TRANS is
CREATE TABLE [dbo].[trans] (
[pin] [char] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[date] [char] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[time] [char] (6) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[type] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[amount] [int] NULL ,
[descr] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[userid] [char] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

The insert is successful on one machine and gives error on one machine.
The error is as follows.
Insert String #8152: String or binary data would be truncated.

I understand that it is complaining that it cannot put '1Œ' value into a char 1 field. But my question is how is it working on the other machine. I traced the table with the profiler and I get the same kind of insert statement on both the machines.

Please help.
Thanks.

gurupot
April 26th, 2007, 12:28 AM
I am using SQL 8.0 on both the machines.

gurupot
April 26th, 2007, 11:27 AM
Here are the version details of both the machines if that helps.
DOES NOT WORK ON
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Standard Edition on Windows NT 5.0 (Build 2195: Service Pack 4)

WORKS ON
Microsoft SQL Server 2000 - 8.00.194 (Intel X86)
Aug 6 2000 00:57:48
Copyright (c) 1988-2000 Microsoft Corporation
Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 2)

Does the standard edition and developer edition make any difference.
If so how do I fix it. Any help is appreciated.

hspc
April 26th, 2007, 11:05 PM
I the same collation used on both servers?

pranay
May 7th, 2007, 12:58 PM
this is the general error you get wen u are passing any string value more in length than the columns allocated length.
for example:
column name Col1 Char(20)

and u are passing the value to be inserted as 'aaaaaaaaaaaaaaaaaaaaaaaa'

here the length passed is 24 chars and the column length is char (20) only.

such cases in general gives the error you mentioned. still am not sure if this is the cause of ur error or not. :thumb:

pranay
May 7th, 2007, 01:01 PM
i was just looking in the code u provided, just chek the length of the type column and the value u are passing to it.
column length is char (1) and the value u are passing is 'ICD' so it comes to 3 chars... and hence the error... hope this helps u solving ur probs...
take care!!