- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在调用存储过程来检索值时,在某些情况下(并非全部 - 它对某些数据都可以正常工作),我收到“字符串或二进制数据将被截断”错误消息。
根据 this ,当您尝试插入太长的数据,或者当您尝试乱序添加数据时,就会发生这种情况;后者不是问题,因为它在某些情况下确实有效。这显然是数据问题。
异常消息说“priceUsageVariance”(我的存储过程)的第 75 行是罪魁祸首:
“priceUsageVariance”的第 75 行是:
WHERE ItemCode='X'
这是该存储过程的摘录,以显示更多上下文(表面上有问题的行是最后一行):
. . .
CREATE TABLE #TEMPCOMBINED(
PlatypusNo VARCHAR(6),
PlatypusName VARCHAR(50),
ItemCode VARCHAR(15),
PlatypusItemCode VARCHAR(20),
DuckbillDESCRIPTION VARCHAR(50),
PlatypusDESCRIPTION VARCHAR(200),
WEEK1USAGE DECIMAL(18,2),
WEEK2USAGE DECIMAL(18,2),
USAGEVARIANCE AS WEEK2USAGE - WEEK1USAGE,
WEEK1PRICE DECIMAL(18,2),
WEEK2PRICE DECIMAL(18,2),
PRICEVARIANCE AS WEEK2PRICE - WEEK1PRICE,
PRICEVARIANCEPERCENTAGE AS CAST((WEEK2PRICE - WEEK1PRICE) / NULLIF(WEEK1PRICE,0) AS DECIMAL(18,5))
);
INSERT INTO #TEMPCOMBINED (PlatypusNo, PlatypusName, ItemCode, PlatypusItemCode, DuckbillDESCRIPTION, PlatypusDESCRIPTION,
WEEK1USAGE, WEEK2USAGE, WEEK1PRICE, WEEK2PRICE)
SELECT T1.PlatypusNo, T1.PlatypusName, 'X', T1.PlatypusITEMCODE, NULL, T1.DESCRIPTION, T1.WEEK1USAGE, T2.WEEK2USAGE,
T1.WEEK1PRICE, T2.WEEK2PRICE
FROM #TEMP1 T1
LEFT JOIN #TEMP2 T2 ON T1.PlatypusITEMCODE = T2.PlatypusITEMCODE
UPDATE #TEMPCOMBINED SET ItemCode = ISNULL(
(SELECT TOP 1 ItemCode
FROM MasterPlatypusUnitMapping
WHERE Unit=@Unit
AND PlatypusNo=#TEMPCOMBINED.PlatypusNo
AND PlatypusItemCode = #TEMPCOMBINED.PlatypusItemCode
AND ItemCode IN (SELECT ItemCode FROM UnitProducts WHERE Unit=@Unit)),'X'
)
WHERE ItemCode='X'
. . .
我什至不明白这个问题是怎么可能的——ItemCode 字段正在用 MasterPlatypusUnitMapping 表中的 ItemCode 值更新——它是一个 VarChar(15),与我的#TEMPCOMBINE 表中的相应字段相同- 或带有“X”。这两个值怎么会太大?
给出的行号是否有效/可靠?有没有办法在处理存储过程时单步执行存储过程?
是否有某种解决方法可以防止此异常扰乱工作?
响应 Shnugo 的建议/请求,这里是整个 SP:
这里是:
CREATE Procedure [dbo].[priceAndUsageVariance]
@Unit varchar(25),
@BegDate datetime,
@EndDate datetime
AS
DECLARE @Week1End datetime = DATEADD(Day, 6, @BegDate);
DECLARE @Week2Begin datetime = DATEADD(Day, 7, @BegDate);
// temp1 holds some values for the first week
CREATE TABLE #TEMP1
(
MemberNo VARCHAR(6),
MemberName VARCHAR(50),
MEMBERITEMCODE VARCHAR(25),
DESCRIPTION VARCHAR(50),
WEEK1USAGE DECIMAL(18,2),
WEEK1PRICE DECIMAL(18,2)
);
INSERT INTO #TEMP1 (MemberNo, MemberName, MEMBERITEMCODE, DESCRIPTION,
WEEK1USAGE, WEEK1PRICE)
SELECT INVD.MEMBERNO, MemberName, ITEMCODE, DESCRIPTION, SUM(QTYSHIPPED),
PRICE
FROM INVOICEDETAIL INVD
JOIN MEMBERS M ON INVD.MEMBERNO = M.MEMBERNO
WHERE UNIT=@UNIT AND INVOICEDATE BETWEEN @BEGDATE AND @Week1End
GROUP BY ITEMCODE, DESCRIPTION, PRICE, INVD.MEMBERNO, MemberName
// temp2 holds some values for the second week
CREATE TABLE #TEMP2
(
MemberNo VARCHAR(6),
MemberName VARCHAR(50),
MEMBERITEMCODE VARCHAR(25),
DESCRIPTION VARCHAR(50),
WEEK2USAGE DECIMAL(18,2),
WEEK2PRICE DECIMAL(18,2)
);
INSERT INTO #TEMP2 (MemberNo, MemberName, MEMBERITEMCODE, DESCRIPTION,
WEEK2USAGE, WEEK2PRICE)
SELECT INVD.MEMBERNO, MemberName, ITEMCODE, DESCRIPTION, SUM(QTYSHIPPED),
PRICE
FROM INVOICEDETAIL INVD
JOIN MEMBERS M ON INVD.MEMBERNO = M.MEMBERNO
WHERE UNIT=@UNIT AND INVOICEDATE BETWEEN @Week2Begin AND @ENDDATE
GROUP BY ITEMCODE, DESCRIPTION, PRICE, INVD.MEMBERNO, MemberName
// Now tempCombined gets the shared values from temp1 as well as the unique
vals from temp1 and the unique vals from temp2
CREATE TABLE #TEMPCOMBINED(
MemberNo VARCHAR(6),
MemberName VARCHAR(50),
ItemCode VARCHAR(15),
MemberItemCode VARCHAR(20),
PlatypusDESCRIPTION VARCHAR(50),
MEMBERDESCRIPTION VARCHAR(200),
WEEK1USAGE DECIMAL(18,2),
WEEK2USAGE DECIMAL(18,2),
USAGEVARIANCE AS WEEK2USAGE - WEEK1USAGE,
WEEK1PRICE DECIMAL(18,2),
WEEK2PRICE DECIMAL(18,2),
PRICEVARIANCE AS WEEK2PRICE - WEEK1PRICE,
PRICEVARIANCEPERCENTAGE AS CAST((WEEK2PRICE - WEEK1PRICE) /
NULLIF(WEEK1PRICE,0) AS DECIMAL(18,5))
);
INSERT INTO #TEMPCOMBINED (MemberNo, MemberName, ItemCode, MemberItemCode,
PlatypusDESCRIPTION, MEMBERDESCRIPTION,
WEEK1USAGE, WEEK2USAGE, WEEK1PRICE, WEEK2PRICE)
SELECT T1.MemberNo, T1.MemberName, 'X', T1.MEMBERITEMCODE, NULL,
T1.DESCRIPTION,
T1.WEEK1USAGE, T2.WEEK2USAGE,
T1.WEEK1PRICE, T2.WEEK2PRICE
FROM #TEMP1 T1
LEFT JOIN #TEMP2 T2 ON T1.MEMBERITEMCODE = T2.MEMBERITEMCODE
// Now some mumbo-jumbo is performed to display the "general" description
rather than the "localized" description
UPDATE #TEMPCOMBINED SET ItemCode = ISNULL(
(SELECT TOP 1 ItemCode
FROM MasterMemberUnitMapping
WHERE Unit=@Unit
AND MemberNo=#TEMPCOMBINED.MemberNo
AND MemberItemCode = #TEMPCOMBINED.MemberItemCode
AND ItemCode IN (SELECT ItemCode FROM UnitProducts WHERE Unit=@Unit)),'X'
)
WHERE ItemCode='X'
UPDATE #TEMPCOMBINED SET ItemCode = ISNULL(
(SELECT TOP 1 ItemCode FROM MasterMemberMapping WHERE
MemberNo=#TEMPCOMBINED.MemberNo AND MemberItemCode + PackType =
#TEMPCOMBINED.MemberItemCode ),'X'
)
WHERE ItemCode='X'
UPDATE #TEMPCOMBINED SET PlatypusDESCRIPTION = ISNULL(MP.Description,'')
FROM #TEMPCOMBINED TC
INNER JOIN MasterProducts MP ON MP.Itemcode=TC.ItemCode
// finally, what is hoped to be the desired amalgamation is returned
SELECT TC.PlatypusDESCRIPTION, TC.MemberName, TC.WEEK1USAGE, TC.WEEK2USAGE,
TC.USAGEVARIANCE, TC.WEEK1PRICE, TC.WEEK2PRICE, TC.PRICEVARIANCE,
TC.PRICEVARIANCEPERCENTAGE
FROM #TEMPCOMBINED TC
ORDER BY TC.PlatypusDESCRIPTION, TC.MemberName;
我也在尝试使它现代化,改编 Schnugo 的代码,但是这样:
CREATE FUNCTION [dbo].[priceAndUsageVarianceTVF]
(
@Unit varchar(25),
@BegDate datetime,
@EndDate datetime
)
RETURNS TABLE
AS
RETURN
WITH Dates aS
(
SELECT DATEADD(Day, 6, @BegDate) AS Week1End
,DATEADD(Day, 7, @BegDate) AS Week2Begin
)
,Temp1 AS
(
SELECT INVD.MEMBERNO, MemberName, ITEMCODE AS MEMBERITEMCODE, DESCRIPTION, SUM(QTYSHIPPED) AS WEEK1USAGE,
PRICE AS WEEK1PRICE
FROM INVOICEDETAIL INVD
JOIN MEMBERS M ON INVD.MEMBERNO = M.MEMBERNO
WHERE UNIT=@UNIT AND INVOICEDATE BETWEEN @BEGDATE AND (SELECT Week1End FROM Dates)
GROUP BY ITEMCODE, DESCRIPTION, PRICE, INVD.MEMBERNO, MemberName
)
,Temp2 AS
(
SELECT INVD.MEMBERNO, MemberName, ITEMCODE AS MEMBERITEMCODE, DESCRIPTION, SUM(QTYSHIPPED) AS WEEK2USAGE,
PRICE AS WEEK2PRICE
FROM INVOICEDETAIL INVD
JOIN MEMBERS M ON INVD.MEMBERNO = M.MEMBERNO
WHERE UNIT=@UNIT AND INVOICEDATE BETWEEN (SELECT Week2Begin FROM Dates) AND @ENDDATE
GROUP BY ITEMCODE, DESCRIPTION, PRICE, INVD.MEMBERNO, MemberName
)
,TempCombined AS
(
SELECT T1.MemberNo, T1.MemberName, T1.MEMBERITEMCODE, NULL AS PLATYPUSDESCRIPTION,
T1.DESCRIPTION,
T1.WEEK1USAGE, T2.WEEK2USAGE,
T1.WEEK1PRICE, T2.WEEK2PRICE
FROM Temp1 T1
LEFT JOIN Temp2 T2 ON T1.MEMBERITEMCODE = T2.MEMBERITEMCODE
)
SELECT ROW_NUMBER() OVER(ORDER BY TC.PLATYPUSDESCRIPTION, TC.MemberName) AS RowInxToGetASortOrder,
ISNULL(MP.Description,'') AS PLATYPUSDESCRIPTION,
TC.MemberName, TC.WEEK1USAGE, TC.WEEK2USAGE,
TC.USAGEVARIANCE AS T2.WEEK2USAGE - T1.WEEK1USAGE,
TC.WEEK1PRICE, TC.WEEK2PRICE,
TC.PRICEVARIANCE AS T2.WEEK2PRICE - T1.WEEK1PRICE,
TC.PRICEVARIANCEPERCENTAGE AS CAST((T2.WEEK2PRICE - T1.WEEK1PRICE) / NULLIF(T1.WEEK1PRICE,0) AS DECIMAL(18,5))
FROM TempCombined TC
LEFT JOIN Temp2 T2 ON T1.MEMBERITEMCODE = T2.MEMBERITEMCODE
--LEFT JOIN MasterProducts MP ON MP.Itemcode=ISNULL(ItemCode_Try1.ItemCode, ItemCode_Try2.ItemCode)
LEFT JOIN MasterProducts MP ON MP.Itemcode=ISNULL(ItemCode_Try1.ItemCode, ItemCode_Try2.ItemCode)
CROSS APPLY
(
SELECT TOP 1 ItemCode
FROM MasterMemberUnitMapping
WHERE Unit=@Unit
AND MemberNo=TC.MemberNo
AND MemberItemCode = TC.MemberItemCode
AND ItemCode IN (SELECT ItemCode FROM UnitProducts WHERE Unit=@Unit)
) AS ItemCode_Try1(ItemCode)
CROSS APPLY
(
SELECT TOP 1 ItemCode
FROM MasterMemberMapping
WHERE MemberNo=TC.MemberNo
AND MemberItemCode + PackType = TC.MemberItemCode
) AS ItemCode_Try2(ItemCode)
;
...我收到以下错误消息:
Msg 102, Level 15, State 1, Procedure priceAndUsageVarianceTVF, Line 45
Incorrect syntax near '.'.
Msg 156, Level 15, State 1, Procedure priceAndUsageVarianceTVF, Line 61
Incorrect syntax near the keyword 'AS'.
Msg 156, Level 15, State 1, Procedure priceAndUsageVarianceTVF, Line 68
Incorrect syntax near the keyword 'AS'.
消息 102 在这一行:
TC.USAGEVARIANCE AS T2.WEEK2USAGE - T1.WEEK1USAGE,
(在 T2.WEEK2USAGE 下方有红色波浪线)
消息 156 在最后两个“AS”行上,即:
AS ItemCode_Try1(ItemCode)
...还有这个:
) AS ItemCode_Try2(ItemCode)
最佳答案
我仍然不知道原因,可能是您连接 MemberItemCode + PackType
...
但是:
这样的 StoredProcedure 非常过时这是一个经典示例,其中可内联(即席)表值函数将是更好的方法。
在不了解您的数据库并且没有机会测试某些东西的情况下,以下建议肯定不会“开箱即用”,但您可能会想到如何可以极大地加快速度。作为副作用,您将摆脱提到的错误,因为查询引擎将处理原始列,并且不必将值从一个地方复制到具有截断效果的(最终更小的)列:
我敢肯定,这种结构远非最佳结构,但在不知道细节的情况下,我别无选择,只能复制和改编您在 SP 中定义的代码块。特别是涉及到你的“胡言乱语”:-) 我不太确定,如果我的想法正确......
CREATE FUNCTION [dbo].[priceAndUsageVariance]
(
@Unit varchar(25),
@BegDate datetime,
@EndDate datetime
)
RETURNS TABLE
AS
RETURN
WITH Dates aS
(
SELECT DATEADD(Day, 6, @BegDate) AS Week1End
,DATEADD(Day, 7, @BegDate) AS Week2Begin
)
,Temp1 AS
(
SELECT INVD.MEMBERNO, MemberName, ITEMCODE, DESCRIPTION, SUM(QTYSHIPPED),
PRICE
FROM INVOICEDETAIL INVD
JOIN MEMBERS M ON INVD.MEMBERNO = M.MEMBERNO
WHERE UNIT=@UNIT AND INVOICEDATE BETWEEN @BEGDATE AND (SELECT Week1End FROM Dates)
GROUP BY ITEMCODE, DESCRIPTION, PRICE, INVD.MEMBERNO, MemberName
)
,Temp2 AS
(
SELECT INVD.MEMBERNO, MemberName, ITEMCODE, DESCRIPTION, SUM(QTYSHIPPED),
PRICE
FROM INVOICEDETAIL INVD
JOIN MEMBERS M ON INVD.MEMBERNO = M.MEMBERNO
WHERE UNIT=@UNIT AND INVOICEDATE BETWEEN (SELECT Week2Begin FROM Dates) AND @ENDDATE
GROUP BY ITEMCODE, DESCRIPTION, PRICE, INVD.MEMBERNO, MemberName
)
,TempCombined AS
(
SELECT T1.MemberNo, T1.MemberName, 'X', T1.MEMBERITEMCODE, NULL,
T1.DESCRIPTION,
T1.WEEK1USAGE, T2.WEEK2USAGE,
T1.WEEK1PRICE, T2.WEEK2PRICE
FROM Temp1 T1
LEFT JOIN Temp2 T2 ON T1.MEMBERITEMCODE = T2.MEMBERITEMCODE
)
SELECT ROW_NUMBER() OVER(ORDER BY TC.PlatypusDESCRIPTION, TC.MemberName) AS RowInxToGetASortOrder,
ISNULL(MP.Description,'') AS PlatypusDESCRIPTION,
TC.MemberName, TC.WEEK1USAGE, TC.WEEK2USAGE,
TC.USAGEVARIANCE, TC.WEEK1PRICE, TC.WEEK2PRICE, TC.PRICEVARIANCE,
TC.PRICEVARIANCEPERCENTAGE
FROM TempCombined TC
LEFT JOIN MasterProducts MP ON MP.Itemcode=ISNULL(ItemCode_Try1.ItemCode,ItemCode_Try2.ItemCode)
CROSS APPLY
(
SELECT TOP 1 ItemCode
FROM MasterMemberUnitMapping
WHERE Unit=@Unit
AND MemberNo=TC.MemberNo
AND MemberItemCode = TC.MemberItemCode
AND ItemCode IN (SELECT ItemCode FROM UnitProducts WHERE Unit=@Unit)
) AS ItemCode_Try1(ItemCode)
CROSS APPLY
(
SELECT TOP 1 ItemCode
FROM MasterMemberMapping
WHERE MemberNo=TC.MemberNo
AND MemberItemCode + PackType = TC.MemberItemCode
) AS ItemCode_Try2(ItemCode)
;
关于sql-server - 当更新的值不是太长时,我怎么能得到 "String or binary data would be truncated"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34966022/
SQLite、Content provider 和 Shared Preference 之间的所有已知区别。 但我想知道什么时候需要根据情况使用 SQLite 或 Content Provider 或
警告:我正在使用一个我无法完全控制的后端,所以我正在努力解决 Backbone 中的一些注意事项,这些注意事项可能在其他地方更好地解决......不幸的是,我别无选择,只能在这里处理它们! 所以,我的
我一整天都在挣扎。我的预输入搜索表达式与远程 json 数据完美配合。但是当我尝试使用相同的 json 数据作为预取数据时,建议为空。点击第一个标志后,我收到预定义消息“无法找到任何内容...”,结果
我正在制作一个模拟 NHL 选秀彩票的程序,其中屏幕右侧应该有一个 JTextField,并且在左侧绘制弹跳的选秀球。我创建了一个名为 Ball 的类,它实现了 Runnable,并在我的主 Draf
这个问题已经有答案了: How can I calculate a time span in Java and format the output? (18 个回答) 已关闭 9 年前。 这是我的代码
我有一个 ASP.NET Web API 应用程序在我的本地 IIS 实例上运行。 Web 应用程序配置有 CORS。我调用的 Web API 方法类似于: [POST("/API/{foo}/{ba
我将用户输入的时间和日期作为: DatePicker dp = (DatePicker) findViewById(R.id.datePicker); TimePicker tp = (TimePic
放宽“邻居”的标准是否足够,或者是否有其他标准行动可以采取? 最佳答案 如果所有相邻解决方案都是 Tabu,则听起来您的 Tabu 列表的大小太长或您的释放策略太严格。一个好的 Tabu 列表长度是
我正在阅读来自 cppreference 的代码示例: #include #include #include #include template void print_queue(T& q)
我快疯了,我试图理解工具提示的行为,但没有成功。 1. 第一个问题是当我尝试通过插件(按钮 1)在点击事件中使用它时 -> 如果您转到 Fiddle,您会在“内容”内看到该函数' 每次点击都会调用该属
我在功能组件中有以下代码: const [ folder, setFolder ] = useState([]); const folderData = useContext(FolderContex
我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequest 和 NSURLSession 获取图像,但是当我使用 AFHT
我正在使用 Oracle ojdbc 12 和 Java 8 处理 Oracle UCP 管理器的问题。当 UCP 池启动失败时,我希望关闭它创建的连接。 当池初始化期间遇到 ORA-02391:超过
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve
引用这个plunker: https://plnkr.co/edit/GWsbdDWVvBYNMqyxzlLY?p=preview 我在 styles.css 文件和 src/app.ts 文件中指定
为什么我的条形这么细?我尝试将宽度设置为 1,它们变得非常厚。我不知道还能尝试什么。默认厚度为 0.8,这是应该的样子吗? import matplotlib.pyplot as plt import
当我编写时,查询按预期执行: SELECT id, day2.count - day1.count AS diff FROM day1 NATURAL JOIN day2; 但我真正想要的是右连接。当
我有以下时间数据: 0 08/01/16 13:07:46,335437 1 18/02/16 08:40:40,565575 2 14/01/16 22:2
一些背景知识 -我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端
我面临着一个愚蠢的问题。我试图在我的 Angular 应用程序中延迟加载我的图像,我已经尝试过这个2: 但是他们都设置了 src attr 而不是 data-src,我在这里遗漏了什么吗?保留 d
我是一名优秀的程序员,十分优秀!