CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Insert errors

  1. #1
    Join Date
    Nov 2003
    Posts
    107

    Insert errors

    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.

  2. #2
    Join Date
    Nov 2003
    Posts
    107

    Re: Insert errors

    I am using SQL 8.0 on both the machines.

  3. #3
    Join Date
    Nov 2003
    Posts
    107

    Angry Re: Insert errors

    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.

  4. #4
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    Re: Insert errors

    I the same collation used on both servers?
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

  5. #5
    Join Date
    May 1999
    Location
    New Delhi, India
    Posts
    359

    Re: Insert errors

    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.
    Whenever I hear "It can't be done", I know, I am close to success!!

  6. #6
    Join Date
    May 1999
    Location
    New Delhi, India
    Posts
    359

    Re: Insert errors

    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!!
    Whenever I hear "It can't be done", I know, I am close to success!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured