存储过程难度大

时间:2018-02-06 16:55:32

标签: sql sql-server stored-procedures

我正在使用SQL Server而且我遇到了问题。任何帮助,将不胜感激!

使用AP数据库创建一个名为double d = accumulate(vectOrd.begin(), vectOrd.end(), 0.0, [](double acc, const Order& order) { return acc + order.gesamtpreisEinerPerson(); }); 的存储过程,该过程接受两个参数:类型为double operator+ (double d, const Order& order) { return d + order.gesamtpreisEinerPerson(); } 的{​​{1}}和类型为spFindInvoices的{​​{1}}。

此过程显示VendorName,InvoiceNumber,InvoiceDueDate和@NameVendor的余额,其中余额大于@BalanceLimit。如果您使用@NameVendorvarchar来调用/测试该过程,则会显示以下表格:

@BalanceLimit

2 个答案:

答案 0 :(得分:0)

我不完全确定我是否掌握了您的要求,但如果我是正确的,我相信您正在为指定的供应商寻找超过指定金额的所有余额

USE AP;
GO

CREATE PROC spInvoices
     @NameVendor VARCHAR(50),
     @BalanceLimit SMALLMONEY
AS
    SELECT 
        VendorName, InvoiceNumber, InvoiceDueDate, 
        (InvoiceTotal - CreditTotal - PaymentTotal) AS Balance
    FROM 
        Invoices 
    JOIN 
        Vendors ON Invoices.VendorID = Vendors.VendorID
    WHERE 
        @BalanceLimit > (InvoiceTotal - CreditTotal - PaymentTotal)
    AND 
        @NameVendor = VendorName
GO

EXEC spFindInvoices @NameVendor = 'Federal Express Corporation',
                @BalanceLimit = '0' 

您应该将VARCHAR @VendorName和SMALLMONEY @BalanceLimit相互比较,当您将它们与查询中的相应值进行比较时

答案 1 :(得分:0)

此代码应该有效:

CREATE PROC spInvoices
     @NameVendor VARCHAR(50),
     @BalanceLimit SMALLMONEY
AS
    SELECT 
        VendorName, InvoiceNumber, InvoiceDueDate, 
        (InvoiceTotal - CreditTotal - PaymentTotal) AS Balance
    FROM 
        Invoices 
    JOIN 
        Vendors ON Invoices.VendorID = Vendors.VendorID
    WHERE 
        @NameVendor  = Vendors.VendorName
        (InvoiceTotal - CreditTotal - PaymentTotal) > @BalanceLimit

但是,如果列的其他类型不是InvoiceTotal,则可能需要明确地将列添加到CreditTotalPaymentTotalsmallmoneysmallmoney datattytpe。