为我们的M1 erp软件创建标签的问题

时间:2019-08-21 20:23:29

标签: sql-server tsql

我正在尝试转换为我们的软件的先前版本编写的SQL。它正在从输入表单中获取信息,将其放置在临时表中并计算标签数量并相应地打印水晶报告标签

我试图更改语法并删除无法链接到新版本中任何内容的where子句(在下面的代码中已注释掉)。

SET NOCOUNT ON
DECLARE @nloop int, @nLabels int
DECLARE @rmlReceiptID varchar(10), @rmlReceiptLineID int, @urmlNOofLabels int
DECLARE LabelsCursor CURSOR READ_ONLY FOR SELECT @rmlReceiptID, @rmlReceiptLineID, @urmlNOofLabels FROM ReceiptLines /* WHERE {?WHERECLAUSE}*/ ORDER BY rmlReceiptID, rmlReceiptLineID

CREATE TABLE #UReceiptLabel (rmlReceiptID varchar(10), rmlReceiptLineID int, CurrentLabel int, TotalLabels int) 
SELECT @rmlReceiptID,@rmlReceiptLineID,CONVERT(int,0) As CurrentLabel,CONVERT(int,0) As TotalLabels insert into #UReceiptLabel from ReceiptLines WHERE 0=1

OPEN LabelsCursor

FETCH NEXT FROM LabelsCursor INTO @rmlReceiptID, @rmlReceiptLineID, @urmlNOofLabels

WHILE @@FETCH_STATUS = 0
BEGIN
    SET @nloop = 0
    SET @nLabels = @urmlNOofLabels
    IF @nLabels < 1
        SET @nLabels = 1

    WHILE (@nloop < @nLabels)
    BEGIN
        SET @nloop = @nloop + 1
        INSERT INTO #UReceiptLabel (rmlReceiptID, rmlReceiptLineID, CurrentLabel, TotalLabels) VALUES (@rmlReceiptID, @rmlReceiptLineID, @nloop, @nLabels)
    END
    FETCH NEXT FROM LabelsCursor INTO @rmlReceiptID, @rmlReceiptLineID, @urmlNOofLabels
END

CLOSE LabelsCursor
DEALLOCATE LabelsCursor
SET NOCOUNT OFF
SELECT CurrentLabel, TotalLabels, ReceiptLines.rmlReceiptID, ReceiptLines.rmlReceiptLineID, rmlJobID, rmlPartID, rmlJobQuantityReceived, urmlNoOfLabels, urmlQtyInABox, urmlLocation,rmpSupplierOrganizationID, cmoName, rmlDescription, rmlJobAssemblyID
FROM #UReceiptLabel 
INNER JOIN ReceiptLines ON ReceiptLines.rmlReceiptID = #UReceiptLabel.rmlReceiptID and ReceiptLines.rmlReceiptLineID = #UReceiptLabel.rmlReceiptLineID 
LEFT OUTER JOIN Receipts ON rmpReceiptID = #UReceiptLabel.rmlReceiptID 
LEFT OUTER JOIN Organizations On rmpSupplierOrganizationID=cmoOrganizationID ORDER BY #UReceiptLabel.rmlReceiptID,#UReceiptLabel.rmlReceiptLineID,CurrentLabel
DROP TABLE #UReceiptLabel 

当我尝试运行Crystal报表时,我得到一个对象或列名称丢失或为空。对于SELECT INTO语句,请验证每个列都有一个名称。 我希望水晶报表能够解析输入数据,并用适当的信息填充标签并打印正确数量的标签。

0 个答案:

没有答案