Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 String or binary data would be truncated

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2007-12-10 : 15:41:20
Pleeease help, trying to figure out why am i getting this error:
String or binary data would be truncated.

checked the database field size also for contractdescription(varchar(4000)

if i try to add with small info less than 50 chars it works fine, when i try to save more info for field contractdescription i am getting the above error:

i tried executing the SP from query analyzer: copied my whole query , plus stored procedure plus also showing the table design. please help.


following is the stored proc exec info:

exec USP_NewContract 0,0,1,1,'newctr545','newctr545','newctr545','The majority concluded today that a district judge in Virginia acted properly in April 2005 when he refused to follow.','newctr545','newctr545','newctr545','','','','','','admin','',0,'12/10/2007'


Msg 8152, Level 16, State 13, Procedure USP_NewContract, Line 39
String or binary data would be truncated.
The statement has been terminated.


Here is the stored Procedure:

**********************************************************************
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

ALTER PROCEDURE [dbo].[USP_NewContract]
(@ElementID int,
@PhaseID int,
@ProjID int,
@ProgID int,
@ContractNO nvarchar(50),
@ContractCode nvarchar(50),
@ContractName nvarchar(50),
@ContractDescription nvarchar(4000),
@ContractType nvarchar(50),
@ContractorName nvarchar(50),
@Designer nvarchar(50),
@ConstructionMgr nvarchar(50),
@Area nvarchar(50),
@Status nvarchar(50),
@PercentComplete int,
@ClaimFactor nvarchar(50),
@UserName nvarchar(50),
@CWONO nvarchar(50),
@Identity int OUTPUT,
@LockStartTime datetime OUTPUT)


AS
DECLARE @ErrorCode int
DECLARE @TransactionCountOnEntry int


SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
SELECT @ErrorCode = @@Error, @TransactionCountOnEntry = @@TranCount
IF @ErrorCode = 0
BEGIN
BEGIN TRANSACTION
SET @LockStartTime = GetDate()
INSERT INTO TAB_ccsNetContracts
(ElementID,
PhaseID,
ProjID,
ProgID,
ContractNO,
ContractCode,
ContractName,
ContractDescription,
ContractType,
ContractorName,
Designer,
ConstructionMgr,
Area,
Status,
PercentComplete,
ClaimFactor,
CWO,
Deleted,
RecordLocked,
LockedBy,
LockStartTime,
UpdatedBy)
VALUES
(@ElementID,
@PhaseID,
@ProjID,
@ProgID,
@ContractNO,
@ContractCode,
@ContractName,
@ContractType,
@ContractDescription,
@ContractorName,
@Designer,
@ConstructionMgr,
@Area,
@Status,
@PercentComplete,
@ClaimFactor,
@CWONO,
'0',
1,
@UserName,
@LockStartTime,
@UserName)
SELECT @ErrorCode = @@Error
IF @ErrorCode <> 0
BEGIN
ROLLBACK TRANSACTION
SET NOCOUNT OFF
RETURN @ErrorCode
END
SET @Identity = SCOPE_IDENTITY()

INSERT INTO TAB_ccsNetContracts_log
(ContractID,
ElementID,
PhaseID,
ProjID,
ProgID,
ContractNO,
ContractCode,
ContractName,
ContractDescription,
ContractType,
ContractorName,
Designer,
ConstructionMgr,
Area,
Status,
PercentComplete,
ClaimFactor,
CWO,
Deleted,
RecordLocked,
LockedBy,
LockStartTime,
UpdatedBy)
VALUES
(@Identity,
@ElementID,
@PhaseID,
@ProjID,
@ProgID,
@ContractNO,
@ContractCode,
@ContractName,
@ContractType,
@ContractDescription,
@ContractorName,
@Designer,
@ConstructionMgr,
@Area,
@Status,
@PercentComplete,
@ClaimFactor,
@CWONO,
'0',
1,
@UserName,
@LockStartTime,
@UserName)

SELECT @ErrorCode = @@Error
IF @ErrorCode <> 0
BEGIN
ROLLBACK TRANSACTION
SET NOCOUNT OFF
RETURN @ErrorCode
END
END
IF @@TranCount > @TransactionCountOnEntry
COMMIT TRANSACTION
SET NOCOUNT OFF
RETURN @ErrorCode

****************************************************************************************
Table designL contractdescription has 4000

CREATE TABLE [dbo].[TAB_ccsNetContracts](
[ContractID] [int] IDENTITY(1,1) NOT NULL,
[ElementID] [int] NULL,
[PhaseID] [int] NULL,
[ProjID] [int] NOT NULL,
[ProgID] [int] NOT NULL,
[ContractNO] [nvarchar](50) NULL,
[ContractCode] [nvarchar](50) NULL,
[ContractName] [nvarchar](50) NOT NULL,
[ContractDescription] [nvarchar](4000) NULL,
[ContractType] [nvarchar](50) NULL,
[ContractorName] [nvarchar](50) NULL,
[Designer] [nvarchar](50) NULL,
[ConstructionMgr] [nvarchar](50) NULL,
[Area] [nvarchar](50) NULL,
[Status] [nvarchar](50) NULL,
[PercentComplete] [nvarchar](50) NULL,
[ClaimFactor] [nvarchar](50) NULL,
[CWO] [nvarchar](50) NULL,
***************************************************************************


Thank you very much for the information...

cognos79
Posting Yak Master

241 Posts

Posted - 2007-12-10 : 15:51:33
the order of columns you specified in second insert statement insert into TAB_ccsNetContracts is not correct. check the order of columns in insert and values again. there is the error.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-12-10 : 15:56:25
The cause of the error is really obvious.

You need to have the columns in the column list and in the value list in exactly the same order.



CODO ERGO SUM
Go to Top of Page

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2007-12-10 : 16:10:57
Wow... you guys are greeeeaat. Thank you very much.
i did'nt figure that one.

Thanks a lot.........
Go to Top of Page
   

- Advertisement -