简体   繁体   English

T-SQL插入到截断插入时的数据

[英]T-SQL Insert into truncates data on insert

This is odd. 这很奇怪。 I have two separate store procedures inserting into one table. 我有两个单独的存储过程插入到一个表中。

One works fine while the other truncates all but the 1st character on four varchar(50) columns. 一个工作正常,而另一个则截断四个varchar(50)列上除第一个字符外的所有字符。 I've tested this by executing the SP in SQL. 我已经通过在SQL中执行SP进行了测试。

Only difference is the working query is moving data from one table to the other. 唯一的区别是工作查询正在将数据从一个表移动到另一个表。 The non-working stored procedure is receiving parameters. 无效的存储过程正在接收参数。 In the non working query, there are int columns and they work fine. 在非工作查询中,有int列,它们工作正常。 It's just the four varchar. 这只是四个varchar。

This works fine. 这很好。

INSERT INTO PurchaseOrderItems_tbl (POID, VendorAccountID, POTicketID, POInvItemID, POLineItemQty, PartManufPartNum, PartOrderDesc, PartOrderManufacture, PartOrderModel, POType, PODescription, POStatusID, PartRequestedBy, POGLCode)
    SELECT
        POID, VendorAccountID, PartOrderTicketID, PartInvID, 
        POItemQty, PartManufPartNum, PartOrderDesc, 
        PartOrderManufacture, PartOrderModel, POType, 
        PODescription, POStatusID, PartRequestedBy, POGLCode
    FROM
        PurchaseOrderTmp_tbl

This is the non working stored procedure: 这是无效的存储过程:

Procedure [dba].[xxxxx]
(
    @POID int,
    @VendorAccountID int,
    @PartOrderTicketID int,
    @PartInvID int,
    @PartManufPartNum varchar,
    @PartOrderDesc varchar,
    @PartOrderManufacture varchar,
    @PartOrderModel varchar,
    @PartOrderType varchar,
    @PartOrderQTY int   
    )
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
INSERT INTO PurchaseOrderItems_tbl
    ([POID],[VendorAccountID],[POInvItemID],[POTicketID],[PartManufPartNum],[PartOrderDesc],[PartOrderManufacture],[PartOrderModel],[POLineItemQty])

VALUES  (@POID, @VendorAccountID, @PartInvID, @PartOrderTicketID, @PartManufPartNum, @PartOrderDesc, @PartOrderManufacture, @PartOrderModel, @PartOrderQTY)

END

I am completely baffled as I see nothing wrong and the qry does not error. 我完全感到困惑,因为我没有发现任何错误,并且qry不会出错。

Thanks in advance folks 在此先感谢大家

Your stored proc does not specify the length of the varchar inputs - by default this length is 1. 您存储的过程未指定varchar输入的长度 -默认情况下,此长度为1。

procedure [dba].[xxxxx]
(
    @POID int,
    @VendorAccountID int,
    @PartOrderTicketID int,
    @PartInvID int,
    @PartManufPartNum varchar(50), -- match the column length
...etc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM