我发现将数据类型nvarchar转换为bigint时出现了数千个问题,但没有针对我的具体问题的解决方案。我有一个通用表DynamicArticle_ParameterResult,其中值字段可以包含所有内容(数字/文本)。
如果我根据连接(ArticleResultID = DAAR.ID)进行子查询,我会'错误地将数据类型nvarchar转换为bigint':
SELECT OSL.GroupName AS MAINGROUPNAME, DAAR.SalesLineID, DAAR.SalesID, DAAR.ID, spt.number + 1 AS SUBNO, (SELECT Value
FROM DynamicArticle_ParameterResult AS DynamicArticle_ParameterResult_9
WHERE (ArticleResultID = DAAR.ID) AND (Name = 'Panel_Dx')) AS Panel_dx,
(SELECT Value
FROM DynamicArticle_ParameterResult AS DynamicArticle_ParameterResult_8
WHERE (ArticleResultID = DAAR.ID) AND (Name = 'Panel_Dy')) AS Panel_dy,
(SELECT Value
FROM DynamicArticle_ParameterResult AS DynamicArticle_ParameterResult_7
WHERE (ArticleResultID = DAAR.ID) AND (Name = 'Panel_Dz')) AS Panel_dz,
(SELECT Name
FROM ProductManagerConfig.dbo.Colors
WHERE (Id =
(SELECT TOP (1) Value
FROM DynamicArticle_ParameterResult
WHERE (ArticleResultID = DAAR.ID) AND (Name = 'Panel_Color')))) AS COLORNAME, OSL.GroupName AS Soort, ST.LoadDay, ST.RouteNumber, ST.RouteOrderNumber, ST.SalesNumber,
ST.ProductionNumber, Products.GroupName, Products.FullNameFROM DynamicArticle_ArticleResult AS DAAR INNER JOIN
ProductManager_Products AS Products ON Products.ItemID = DAAR.ItemID INNER JOIN
SalesTable AS ST ON ST.Id = DAAR.SalesID INNER JOIN
OrderSalesLines AS OSL ON OSL.SalesLineID = Products.SalesLineID AND OSL.Depth = 0 INNER JOIN
SalesLines AS SL ON SL.Id = Products.SalesLineID INNER JOIN
master.dbo.spt_values AS spt ON spt.type = 'P' AND spt.number < SL.Quantity WHERE (Products.Id IN (116994,116993)) AND (DAAR.Name = 'Panel' OR
DAAR.Name = 'KlassiekPaneel')
如果我在子查询中放置一个过滤器((ArticleResultID IN(1075728,1075669)),它运行正常吗?
SELECT OSL.GroupName AS MAINGROUPNAME, DAAR.SalesLineID, DAAR.SalesID, DAAR.ID, spt.number + 1 AS SUBNO, (SELECT Value FROM DynamicArticle_ParameterResult AS DynamicArticle_ParameterResult_9
WHERE (ArticleResultID IN(1075728,1075669)) AND (Name = 'Panel_Dx')) AS Panel_dx,
(SELECT Value
FROM DynamicArticle_ParameterResult AS DynamicArticle_ParameterResult_8
WHERE (ArticleResultID IN(1075728,1075669)) AND (Name = 'Panel_Dy')) AS Panel_dy,
(SELECT Value
FROM DynamicArticle_ParameterResult AS DynamicArticle_ParameterResult_7
WHERE (ArticleResultID IN(1075728,1075669)) AND (Name = 'Panel_Dz')) AS Panel_dz,
(SELECT Name
FROM ProductManagerConfig.dbo.Colors
WHERE (Id =
(SELECT TOP (1) Value
FROM DynamicArticle_ParameterResult
WHERE (ArticleResultID IN(1075728,1075669)) AND (Name = 'Panel_Color')))) AS COLORNAME, OSL.GroupName AS Soort, ST.LoadDay, ST.RouteNumber, ST.RouteOrderNumber, ST.SalesNumber,
ST.ProductionNumber, Products.GroupName, Products.FullName FROM DynamicArticle_ArticleResult AS DAAR INNER JOIN
ProductManager_Products AS Products ON Products.ItemID = DAAR.ItemID INNER JOIN
SalesTable AS ST ON ST.Id = DAAR.SalesID INNER JOIN
OrderSalesLines AS OSL ON OSL.SalesLineID = Products.SalesLineID AND OSL.Depth = 0 INNER JOIN
SalesLines AS SL ON SL.Id = Products.SalesLineID INNER JOIN
master.dbo.spt_values AS spt ON spt.type = 'P' AND spt.number < SL.Quantity WHERE (Products.Id IN (116994,116993)) AND (DAAR.Name = 'Panel' OR
DAAR.Name = 'KlassiekPaneel')
有没有办法阻止这种转换错误?
亲切的问候,
麦克
答案 0 :(得分:0)
原来我对订单行的加入导致了这个问题。虽然每个产品返回一行。我删除了它,现在运行正常。