I want to create a procedure in which the following details should be displayed:- I have created this query but I am not getting the right results. I have attached the table schema.
TABLES WE ARE USING:- InvoiceData
, CustomerDetails
and InvoiceItems
Table Schema ->
1. InvoiceItems
TABLE1
2. CustomerDetails
Table2
3. InvoiceDetails
enter image description here
There are 2 sections for invoice:-
In the first section of the Invoice, Below details should be displayed.
In the second section of the invoice, the below details should be displayed:-
Invoice Items description section
I am attaching the query below:-
alter Procedure SaveInvoiceDetails
(
@CustomerId varchar(50),
@InvoiceNumber varchar(50),
@InvoiceDate date,
@InvoiceMonth int,
@FromDate date,
@ToDate date,
@Rate int,
@Quantity int,
@ActualAmount int,
@ZoneId int
)
as
set nocount on;
begin
Declare @TotalRows int
Declare @NumPages int
set @TotalRows = 0
Select ROW_NUMBER() over (order by C.CustomerId) as InvoiceRow,
C.CustomerId, I.InvoiceNumber, I.InvoiceDate, I.FromDate, I.ToDate,
I.InvoiceMonth, I.Rate, I.ActualAmount, I.Quantity, C.ZoneId,
C.BillingAmount
into #tempInvoice
from ConsumerMST_LKO C
inner join InvoiceDetails I
on C.CustomerId = I.CustomerId
inner join INVOICEITEMS II
on I.InvoiceNumber = II.INVOICEID
where InvoiceNumber = @InvoiceNumber AND InvoiceDate = @InvoiceDate AND
InvoiceMonth = @InvoiceMonth
AND FromDate =@FromDate AND ToDate = @ToDate AND ActualAmount =
@ActualAmount
set @TotalRows = @@ROWCOUNT
If @TotalRows = 0
Begin
set @TotalRows = @TotalRows + 1
Insert #tempInvoice
(
InvoiceNumber,
InvoiceDate,
InvoiceMonth,
ZoneId,
Rate,
Quantity,
BillingAmount,
FromDate,
ToDate
)
VALUES
(@TotalRows
, ''
,''
,''
,0
,0
,0
,0
,''
,0)
End
End
SELECT * FROM #tempInvoice ORDER BY InvoiceRow asc
return