Hi,
Thanks for help.
I want to seprate invoice data as per month wise.
below i have table.
CREATE TABLE [dbo].[Invoice](
[InvoiceNo] [numeric](18, 0) NULL,
[StartDateTime] [datetime] NULL,
[EndDateTime] [datetime] NULL,
[InvHours] [numeric](18, 2) NULL,
[Amount] [numeric](18, 2) NULL
) ON [PRIMARY]
GO
and the data is given below.
INSERT INTO Invoice ( InvoiceNo, StartDateTime,EndDateTime,InvHours,Amount ) VALUES
(1,'2022-04-28 22:00:00.000','2022-05-02 12:15:00.000', 86.25,3000),
(2,'2022-05-21 12:45:00.000','2022-05-24 04:15:00.000', 63.5,1000),
(3,'2022-05-21 19:00:00.000','2022-05-24 20:45:00.000', 73.75,2000)
if run the query select * from Invoice
below is the result.
InvoiceNo | StartDateTime | EndDateTime | InvHours | Amount |
---|---|---|---|---|
1 | 28-04-2022 22:00 | 02-05-2022 12:15 | 86.25 | 3000 |
2 | 21-05-2022 12:45 | 24-05-2022 04:15 | 63.5 | 1000 |
3 | 21-05-2022 19:00 | 24-05-2022 20:45 | 73.75 | 2000 |
Now the invoiceNo 1 start from 28-04-2022 to 02-05-2022 now i'm looking for query to split the InvoiceNo 1 StartDate 28-04-2022 and end 30-04-2022 and calculate hours and amount.
below result i'm looking for. Amount 3000/86.25=34.78
InvoiceNo | StartDateTime | EndDateTime | InvHours | Amount | This column shows calculation |
---|---|---|---|---|---|
1 | 28-04-2022 22:00 | 30-04-2022 23:59 | 49.98 | 1738.550713 | =49.98*34.78=1738.551 |
1 | 30-04-2022 23:59 | 02-05-2022 12:15 | 36.27 | 1261.449252 | =36.24*34.78=1261.449 |
2 | 21-05-2022 12:45 | 24-05-2022 04:15 | 63.5 | 1000 | |
3 | 21-05-2022 19:00 | 24-05-2022 20:45 | 73.75 | 2000 |
I used datediff to calculate hours manually.
select DATEDIFF(MINUTE,'2022-04-28 22:00:00.000','2022-04-30 23:59:59.000')/60.0
select DATEDIFF(MINUTE,'2022-04-30 23:59:59.000','2022-05-02 12:15:00.000')/60.0
Please help on to make above query.
Thanks & Regards,
Basit.