如何创建发票

时间:2017-07-25 06:10:47

标签: sql-server sql-server-2008 stored-procedures

SELECT        
    dbo.PaymentMaster.Code,
    dbo.PaymentMaster.OrderNo, 
    dbo.PaymentMaster.CustIssueNo, 
    dbo.PaymentMaster.Amount, 
    dbo.CustomerMaster.CustName, 
    dbo.OrderRequestMaster.ORequestQty, 
    InvoiceMaster.SGST,
    InvoiceMaster.CGST,
    InvoiceMaster.SGST,
    InvoiceMaster.SubTotal,
    InvoiceMaster.TotalAmount
FROM 
    dbo.CustomerIssueMaster,
    dbo.PaymentMaster,
    dbo.CustomerMaster,
    dbo.OrderMaster, 
    dbo.OrderRequestMaster, 
    InvoiceMaster 
WHERE (dbo.PaymentMaster.CustIssueNo = dbo.CustomerIssueMaster.CustIssueNo
     OR OrderMaster.OrderNo = PaymentMaster.OrderNo) 
    AND OrderRequestMaster.ORequestNo = OrderMaster.ORequestNo

我想创建所有条件应该匹配的发票但是当有一行应该给出时我没有得到任何行。

我从付款主人那里得到了这个结果。我想要发票主文件中的客户信息,订单请求信息,订单信息和付款信息,包括Code, InvoiceNo, CustNo, InvoiceDate, SubTotal, CGST, SGST, TotalAmount

Code  PaymentNo     OrderNo       CustIssueNo    PaymentMode PaymentStatus Amount PaymentDate InvoiceNo InvoiceDate
4     KCS[P][00004] NULL          KCS[CI][00001] Cash        Paid          500    14:28.3     NULL      NULL
5     KCS[P][00005] KCS[O][00001] NULL           Cash        Paid          2000   22:33.9     NULL      NULL
6     KCS[P][00006] KCS[O][00002] NULL           Cash        Paid          2000   40:38.1     NULL      NULL

我得到了这个结果

1 个答案:

答案 0 :(得分:0)

如果没有任何数据,我们将很难提供帮助。你说一行应符合条件,但很难看出除非你的表只有一条记录,否则只返回一条记录!

我从您的查询中注意到您想要CustName,而不在WHERE子句中包含CustomerMaster - 这将导致麻烦!

请在查询窗口中使用以下代码,并添加任何重要的缺失字段。然后创建一些INSERT行来填充。重新发布此信息,以便我们可以帮助您完成所需的查询:

declare @CustomerIssueMaster table
(
CustIssueNo int
)
declare @PaymentMaster table
(
Code int,
PaymentNo varchar(50),
OrderNo varchar(50),
CustIssueNo varchar(50),
PaymentMode varchar(50),
PaymentStatus varchar(50),
Amount decimal (18,2),
PaymentDate datetime,
InvoiceNo int,
InvoiceDate datetime
)
declare @CustomerMaster table
(
CustName varchar(50)
)
declare @OrderRequestMaster table
(
ORequestQty int,
ORequestNo int
)
declare @InvoiceMaster table
(
SGST decimal(18,2),
CGST decimal(18,2),
SubTotal decimal(18,2),
TotalAmount decimal(18,2)
)
declare @OrderMaster table
(
OrderNo int
)



INSERT INTO @PaymentMaster VALUES(4, 'KCS[P][00004]', NULL, 'KCS[CI][00001]','Cash','Paid',500,'2014-03-28', NULL, NULL)
INSERT INTO @PaymentMaster VALUES(5, 'KCS[P][00005]', 'KCS[O][00001]', NULL, 'Cash','Paid',2000,'2014-03-28', NULL, NULL)
INSERT INTO @PaymentMaster VALUES(6, 'KCS[P][00006]', 'KCS[O][00002]', NULL, 'Cash','Paid',2000,'2014-03-28', NULL, NULL)

SELECT * FROM @PaymentMaster

修改

请注意我修改了@PaymentMaster的结构并给出了三​​个INSERT来模仿你从SELECT * FROM PaymentMaster显示的数据,但有一个例外:我不明白你的PaymentDate应该是什么格式。前两个看起来像时间,但第三个不可能。我只是陷入了假日期。

现在请你为其他表做同样的事吗?我已经向您展示了您需要使用的格式。