none
Msg 8152, Level 16, State 14, Procedure INSERT_ALAT, Line 38 String or binary data would be truncated.

    Question

  • Hi...I'm new in SQL Server 2008 R2 Express

    well, I have stored procedure like this:

    CREATE PROCEDURE INSERT_ALAT

    -- Add the parameters for the stored procedure here

    @IDAlat CHAR(5),

    @NmAlat VARCHAR(35),

    @IDSatuan CHAR(5),

    @IDUkuran CHAR(5),

    @IDTipe CHAR(5),

    @Jumlah INT,

    @Harga MONEY,

    @ModifBy CHAR(10)

    AS

    BEGIN

    -- SET NOCOUNT ON added to prevent extra result sets from

    -- interfering with SELECT statements.

    SET NOCOUNT ON;

     

        -- Insert statements for procedure here

    IF EXISTS(SELECT 1 FROM Alat WHERE IDAlat = @IDAlat)

    UPDATE

    Alat

    SET

    NmAlat = @NmAlat,

    IDSatuan = @IDSatuan,

    IDUkuran = @IDUkuran,

    IDTipe = @IDTipe,

    Jumlah = @Jumlah,

    Harga = @Harga,

    ModifBy = @ModifBy,

    ModifDt = GetDATE()

    WHERE

    IDAlat = @IDAlat

    ELSE

    INSERT INTO

    Alat

    VALUES

    (@IDAlat

    ,@NmAlat

    ,@IDSatuan

    ,@IDUkuran

    ,@IDTipe

    ,@Jumlah

    ,@Harga

    ,@ModifBy

    ,GETDATE())

    END

     

    the problem is when i execute it with

    EXEC INSERT_ALAT 'A-001','Grease','ST-01','UK-01','TP-01',5,5000,'admin'

    it will raise Msg 8152, Level 16, State 14, Procedure INSERT_ALAT, Line 38 String or binary data would be truncated.

    well i really don't have any idea how to solve this, so if anyone can help me it'll be a great...

    Thanks.

    Friday, July 29, 2011 5:24 AM

Answers

All replies

  • Hi,

    Make sure that the size of parameters are compatible with the columns defined in the table


    Thanks and regards, Rishabh , Microsoft Community Contributor
    Friday, July 29, 2011 5:29 AM
  • seems you are not passing the value for @Harga. Please re-check the correctness of the passing parameters and then re-run the EXEC statement.
    -Vinay Pugalia
    If a post answers your question, please click "Mark As Answer" on that post or "Vote as Helpful".
    Web : Inkey Solutions
    Blog : My Blog
    Email : Vinay Pugalia
    Friday, July 29, 2011 5:40 AM
  • Hi wulung,

    please execute the sql of your procedure manually in Visual Management Studio without calling the proc.

    After that you can click on the error message and the Mamangement Studio will show you the erroneous command. Probably it is just like Rishabh replied.

     


    "It's time to kick ass and chew bubble gum... and I'm all outta gum." - Duke Nukem
    Friday, July 29, 2011 5:45 AM
  • Check this very new and very helpful blog post by Denis Gobo

    How to find what column caused the String or binary data would be truncated message


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog
    Friday, July 29, 2011 6:04 AM
    Moderator
  • In addition to the above, defensive programming (like defensive driving) always pays off in terms of better produtivity and higher reliability.

    Simple example for defensive programming:

    Instead of INSERT .... SELECT ... ColumnX....

    do     INSERT .... SELECT ... LEFT(ColumnX, 35)....

    Don't use SELECT * either and specify the INSERT column list.

    Apply explicit CONVERTs, don't rely on implicit conversions.

     


    Kalman Toth, SQL Server & Business Intelligence Training; sqlusa.com

    Tuesday, August 09, 2011 5:02 PM
    Moderator