فرض می کنم که جداولتون این هاست:
Customers
----------
CST_Serial int identity(1, 1)
CST_Code varchar(100) not null
CST_Name varchar(500) not null
CST_Family varchar(500) not null
CST_NationalCode int not null
CST_Tel varchar(20) null
CST_Address varchar(4000) null
.
.
Goods
------
GUD_Serial int identity(1, 1)
GUD_Code varchar(100) not null
GUD_Name varchar(500) not null
GUD_DefaultPrice decimal null
.
.
FactorBodies
-------------
FCB_Serial int identity(1, 1)
FCB_CST int not null related to CST_Serial
FCB_Code int not null
FCB_Date char(10) not null
FCB_Increments decimal not null
FCB_Decrements decimal not null
.
.
FactorItems
------------
FCI_Serial int identity(1, 1)
FCI_FCB int not null related to FCB_Serial
FCI_GUD int not null related to GUD_Serial
FCI_Amount decimal not null
FCI_Price decimal not null
.
.
البته اگر دوستم نیاد بگه داریم منحرفت می کنیم! ()، این یکی از طراحی ها برای کارهای کوچیکه که قرار نیست تفکیک کالایی برای تخفیفات یا مالیات ها اتفاق بیفته.
پس از این طراحی ها، و گذاشتن ریلیشن ها در دی بی، نوبت می رسه به SP ها یا کوئری ها.
برای مشتری و کالا که راحته، برای فاکتورها:
بدنه ی فاکتور:
select *
from FactorBodies
join Customers on CST_Serial = FCB_CST
where
(FCB_Serial = @FCB_Serial or @FCB_Serial = 0)
and
(FCB_CST = @FCB_CST or @FCB_CST = 0)
and
(FCB_Code = @FCB_Code or @FCB_Code = 0)
and
(FCB_Date between @FCB_DateFrom and @FCB_DateTo)
اقلام فاکتور:
select *
from FactorItems
join Goods on GUD_Serial = FCI_GUD
where
(FCI_Serial = @FCI_Serial or @FCI_Serial = 0)
and
(FCI_FCB = @FCI_FCB or @FCI_FCB = 0)
and
(FCI_GUD = @FCI_GUD or @FCI_GUD = 0)
این فقط یکی از راههاست. تاکید : ممکنه کس دیگه بیاد راه دیگه ای ارائه بده. من با توجه به مشخصات داده شده راه دادم (یعنی مطمئنم میادا (خنده هیستریک))
در کدوم مورد ابهام دارید؟