我在 MS SQL 2008 中有一个存储过程,它编译时没有错误,但是当执行存储过程时,我收到错误消息“字符串或二进制数据将被截断”。不幸的是,我无法追踪发生这种情况的地方。
当我开发我的存储过程时,我首先测试了查询,并且它有效。
所以,如果有人能告诉我发生这种情况的地点和原因以及如何解决它,我将不胜感激:
ALTER PROCEDURE [dbo].[sp_Material_Validation]
@ValidType varchar(MAX),
@MaterialID varchar(MAX)
AS
BEGIN
DECLARE
@MessageReturn varchar(100);
SET @MessageReturn = NULL;
IF @ValidType = 'Primary'
Select TOP 1 Valid.StatusMessage
From
(Select MatID,'Property Not Completed' as StatusMessage
From dbo.Properties
WHERE DATALENGTH(ValueString)=0
UNION
Select PrpCount.MatID,'There not all Properties exist' as StatusMessage
From (Select Count(unkey) as unKeyCt, MatID
From Properties
Group By MatID
Having NOT Count(Cast(UnKey as Int)) = 19)AS PrpCount
UNION
SELECT Header,'Material does not exist' as StatusMessage
FROM Materials Item
Where NOT EXISTS (Select ID
FROM MatMaster Mat
WHERE MAT.ID= Item.HEAD)
UNION
SELECT Header,'Material(s) not Complete' as StatusMessage
FROM Materials
Where MatID IN (Select ID
FROM MatMaster
WHERE INC ='Y')) as Valid
Where Valid.MatID = @MaterialID;
IF @MessageReturn IS NOT NULL
UPDATE dbo.Mat_DEV
SET Inco ='Y',
User_Message = @MessageReturn
WHERE MatID = @MaterialID
ELSE
UPDATE dbo.Mat_DEV
SET User_Message = 'No Validation Errors'
WHERE MatID = @MaterialID