SQL语法转换错误与神秘数据

发布于 2024-12-05 12:02:57 字数 2213 浏览 1 评论 0原文

我在 SQL Server 2000 存储过程中收到此消息:

将 varchar 值 '........................' 转换为 a 时出现语法错误 数据类型为 int 的列。

基本上我正在尝试插入数据并在现有的存储过程中使用它,因此我可能插入了错误的数据,但我没有插入'............ ' 任何地方,我都找不到相关的地方。

问题是,我在查询的表中找不到 '............'。找到此错误的来源?

编辑

部分存储过程引发错误:

  Select @iFromLocationID = IsNull(RecID,0)
    From InventoryLocations 
   Where LocItemNumber = @vItemNumber
     And IsNull(SkidNumber,'') <> ''
     And Cast(SkidNumber as int) = @iSkidFlagID
     And Warehouse = @cFromWarehouse
     And Aisle = @cFromAisle 
     And Slot = @cFromSlot 
     And locLevel = @cFromLevel 
     And Bin = @cFromBin 

InventoryLocations 的表架构:

CREATE TABLE [dbo].[InventoryLocations](
    [recid] [int] IDENTITY(1,1) NOT NULL,
    [LocItemNumber] [char](16) NOT NULL,
    [WareHouse] [char](2) NOT NULL,
    [Aisle] [char](3) NOT NULL,
    [Slot] [char](3) NOT NULL,
    [locLevel] [char](2) NOT NULL,
    [Bin] [char](2) NOT NULL,
    [Extra] [char](2) NOT NULL,
    [LocNumber] [char](2) NOT NULL,
    [RollNumber] [char](20) NOT NULL,
    [QuickRoll] [int] NOT NULL,
    [SkidNumber] [char](15) NOT NULL,
    [RollsInStock] [int] NOT NULL,
    [LocQtyOnHand] [float] NOT NULL,
    [LocQtyOnOrder] [float] NOT NULL,
    [LocQtyCommited] [float] NOT NULL,
    [TotalReceived] [float] NOT NULL,
    [TotalIssued] [float] NOT NULL,
    [TotalDollars] [float] NOT NULL,
    [Capacity] [float] NOT NULL,
    [AvailableSpace] [float] NOT NULL,
    [bkey0] [char](30) NULL,
    [bkey1] [char](30) NULL,
    [bkey2] [char](30) NULL,
    [bkey3] [char](14) NULL,
    [LastPhysicalCountDate] [datetime] NULL,
    [LastCycleCountDate] [datetime] NULL,
    [EnteredBy] [varchar](50) NULL,
    [EnteredDateTime] [datetime] NULL,
 CONSTRAINT [IX_InventoryLocations_1] UNIQUE NONCLUSTERED 
(
    [LocItemNumber] ASC,
    [WareHouse] ASC,
    [Aisle] ASC,
    [Slot] ASC,
    [locLevel] ASC,
    [Bin] ASC,
    [Extra] ASC,
    [RollNumber] ASC,
    [SkidNumber] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

I'm getting this message in an SQL Server 2000 stored procedure:

Syntax error converting the varchar value '...............' to a
column of data type int.

Basically I'm trying to insert data and use it in an existing stored procedure, so its possible that I"m inserting bad data, but I'm not inserting '...............' anywhere, and I can't find that anywhere related.

Trouble is, I can't find '...............' anywhere in the table I'm querying. How can I find the source of this error?

EDIT

Part of the Stored Procedure throwing error:

  Select @iFromLocationID = IsNull(RecID,0)
    From InventoryLocations 
   Where LocItemNumber = @vItemNumber
     And IsNull(SkidNumber,'') <> ''
     And Cast(SkidNumber as int) = @iSkidFlagID
     And Warehouse = @cFromWarehouse
     And Aisle = @cFromAisle 
     And Slot = @cFromSlot 
     And locLevel = @cFromLevel 
     And Bin = @cFromBin 

Table Schema for InventoryLocations:

CREATE TABLE [dbo].[InventoryLocations](
    [recid] [int] IDENTITY(1,1) NOT NULL,
    [LocItemNumber] [char](16) NOT NULL,
    [WareHouse] [char](2) NOT NULL,
    [Aisle] [char](3) NOT NULL,
    [Slot] [char](3) NOT NULL,
    [locLevel] [char](2) NOT NULL,
    [Bin] [char](2) NOT NULL,
    [Extra] [char](2) NOT NULL,
    [LocNumber] [char](2) NOT NULL,
    [RollNumber] [char](20) NOT NULL,
    [QuickRoll] [int] NOT NULL,
    [SkidNumber] [char](15) NOT NULL,
    [RollsInStock] [int] NOT NULL,
    [LocQtyOnHand] [float] NOT NULL,
    [LocQtyOnOrder] [float] NOT NULL,
    [LocQtyCommited] [float] NOT NULL,
    [TotalReceived] [float] NOT NULL,
    [TotalIssued] [float] NOT NULL,
    [TotalDollars] [float] NOT NULL,
    [Capacity] [float] NOT NULL,
    [AvailableSpace] [float] NOT NULL,
    [bkey0] [char](30) NULL,
    [bkey1] [char](30) NULL,
    [bkey2] [char](30) NULL,
    [bkey3] [char](14) NULL,
    [LastPhysicalCountDate] [datetime] NULL,
    [LastCycleCountDate] [datetime] NULL,
    [EnteredBy] [varchar](50) NULL,
    [EnteredDateTime] [datetime] NULL,
 CONSTRAINT [IX_InventoryLocations_1] UNIQUE NONCLUSTERED 
(
    [LocItemNumber] ASC,
    [WareHouse] ASC,
    [Aisle] ASC,
    [Slot] ASC,
    [locLevel] ASC,
    [Bin] ASC,
    [Extra] ASC,
    [RollNumber] ASC,
    [SkidNumber] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

栖竹 2024-12-12 12:02:57

如果您正在构建动态 SQL,请尝试在执行之前打印查询。如果没有,请尝试在编辑器中单独运行存储过程中的查询。如果您有 INSERT..SELECT,请尝试仅运行查询的 SELECT 部分。

If you're building dynamic sql, try printing the query before executing it. If not, try running the queries in the stored procedure individually in an editor. If you have an INSERT..SELECT, try only running the SELECT part of the query.

梦途 2024-12-12 12:02:57

这一定是问题所在:

 And IsNull(SkidNumber,'') <> ''
 And Cast(SkidNumber as int) = @iSkidFlagID

尝试运行以下命令,看看是否出现错误:

SELECT CAST(SkidNumber as INT)
FROM InventoryLocations

由于 @iSkidFlagID 是 INT 并且 SkidNumber 是 CHAR(15),因此它必须是错误发生的地方。

This has to be the issue:

 And IsNull(SkidNumber,'') <> ''
 And Cast(SkidNumber as int) = @iSkidFlagID

Try running the following and see if you get an error:

SELECT CAST(SkidNumber as INT)
FROM InventoryLocations

Since @iSkidFlagID is an INT and SkidNumber is CHAR(15) it has to be where the error is occurring.

一个人练习一个人 2024-12-12 12:02:57

看起来 null 值导致 SQL 返回“.................”。我已经更改了要插入的值,现在我不再收到该错误了。

It looks like a null value was causing SQL to return the '..................'. I've changed the values I'm inserting and now I don't get that error anymore.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文