14-10-21, 02:26 PM
(آخر تعديل لهذه المشاركة : 14-10-21, 02:51 PM {2} بواسطة asemshahen5.)
اخي العزيز كل ما طلبته موجود في الاستعلام و أضفت الاستعلام الشرح لكي تفهمه على فكرة أول سجل في الصورة الثانية هو الرصيد السابق :
PHP كود :
use QtnDB1;
-- حذف جدول ان وجد
if OBJECT_ID('tempdb..#temp') is not null
begin
drop table #temp
PRINT 'Exist'
end
-- إنشاء الجدولمختصر عن دفتر اليومية
CREATE TABLE #temp
(
[DebitAccount] [decimal](18, 2) NOT NULL,
[CreditAccount] [decimal](18, 2) NOT NULL,
[BalanceAccount] [decimal](18, 2) NOT NULL,
[AccountID] [int] NOT NULL,
[AccountName] [nvarchar](50) NOT NULL,
[AccountStatement] [nvarchar](50) NOT NULL,
[AccountDate] [date] NOT NULL,
[AutoNumbering] [int] NOT NULL,
) ON [PRIMARY]
-- تفريغ الجدول
delete from #temp
-- هذا إستعلام إضافة سجل رصيد الزبون قبل البحث بين تاريخين
insert into #temp (DebitAccount,CreditAccount,BalanceAccount,AccountID,AccountName,AccountStatement,AccountDate,AutoNumbering)
(Select Sum(DebitAccount)As DebitAccount,Sum(CreditAccount)As CreditAccount,Sum(DebitAccount)-Sum(CreditAccount)As BalanceAccount,AccountID,AccountName,N'رصيد سابق','2020-09-09',1 From DayBook Where AccountDate < '2020-09-10' And AccountID=1811
group by AccountID,AccountName)
-- جلب سجل الرصيد و معلوماته
select * from #temp
-- دمج النتيجتين الخاصتين بكشف الحساب
UNION ALL
-- إستعلام البحث عن حساب بين تاريخين
Select Sum(DebitAccount)As DebitAccount,Sum(CreditAccount)As CreditAccount,Sum(DebitAccount)-Sum(CreditAccount)As BalanceAccount,AccountID,AccountName,AccountStatement,AccountDate,AutoNumbering From DayBook Where AccountDate Between '2020-09-10' And '2021-04-15' And AccountID=1811
group by AccountID,AccountName,AccountStatement,AccountDate,AutoNumbering;
سبحان الله وبحمده سبحان الله العظيم و الحمد لله ولا اله الا الله والله اكبر
