我写了一个存储过程。
我的要求是我必须显示数据,例如是否有任何列有不同的 Account_Names 我必须显示像 Account_Name :Multipul(varchar))
Create PROCEDURE [dbo].[OpenVendorBIllsSP] (@FromDate Date,@ToDate Date)
AS
BEGIN
select
ROW_NUMBER() OVER(Order by vendor.VendorName ) AS ID,
PH.PurchasingHeaderID as No,
PH.TotalPriceCompanyCurrency as Balance,
acc.AccountName as [Account_Name],
PD.LineMemo as Memo,
from PurchasingHeader PH
LEFT OUTER JOIN TransactionType Trans ON PH.TransactionTypeID =Trans.TransactionTypeID
LEFT OUTER JOIN Vendor vendor on PH.VendorID=vendor.VendorID
LEFT OUTER JOIN PaymentTerm PT on PT.PaymentTermID = vendor.PaymentTermID
LEFT OUTER JOIN PurchasingDetail PD on PD.PurchasingHeaderID = PH.PurchasingHeaderID
LEFT OUTER JOIN Account Acc on Acc.AccountID= PD.FinancialAccountID
where PH.TransactionTypeID=7
Group by vendor.VendorName,
PH.PurchasingHeaderID,PH.TotalPriceCompanyCurrency,acc.AccountName
END
GO
结果:
ID No Account_Name Balance Memo**
-------------------------------------------------------------
101 VB1000 Cash-Petty Cash 4000.00 Memo
102 VB1001 Accounts Receivable 5000.00 Memo
103 VB1003 Cash-PettyCash 6000.00 Memo
104 VB1003 Cash-PettyCash 6000.00 Memo
105 VB1004 UndepositedFunds 7000.00 Memo
我需要这个结果:
ID No Account_Name Balance Memo
------------------------------------------------------
101 VB1000 Cash-PettyCash 4000.00 Memo1
102 VB1001 AccountsReceivable 5000.00 Memo2
103 VB1003 ---Multiple---- 6000.00 Memo3
104 VB1004 UndepositedFunds 7000.00 Memo4
谁能告诉我如何编写 sp 以获得 aboue 结果。
编辑SP:
选择
ROW_NUMBER() OVER(Order by vendor.VendorName ) AS ZID,
PH.PurchasingHeaderID 为否,
PH.TotalPriceCompanyCurrency 作为余额,
案例当 count(PH.PurchasingHeaderID) > 1 然后 'Multipul' 否则 acc.AccountName END
来自 PurchasingHeader PH
左外连接 TransactionType Trans ON PH.TransactionTypeID =Trans.TransactionTypeID
PH.VendorID=vendor.VendorID 上的 LEFT OUTER JOIN 供应商供应商
左外连接 PaymentTerm PT on PT.PaymentTermID = vendor.PaymentTermID
左外连接 PurchasingDetail PD on PD.PurchasingHeaderID = PH.PurchasingHeaderID
LEFT OUTER JOIN Account Acc on Acc.AccountID= PD.FinancialAccountID
其中 PH.TransactionTypeID=7
按 vendor.VendorName,PH.PurchasingHeaderID 分组,
PH.PurchasingHeaderID,PH.TotalPriceCompanyCurrency,acc.AccountName