vendredi 26 août 2016

SQL - SHOW DATA OF TABLE1(PK) WITHOUT HAVING DATA IN TABLE 2(FK)

there are two tables Customer and Fees (PK customer.CustomerID -> Fees.CustomerId FK) there are customers in Customer table. where in table Fees there is no data of current month. without inserting data in Fees table of current month i want to show the Customer details from Customer table of whom have not paid the fees of current month.

something like:

if(Convert(varchar(3),MonthFee, 109) != convert(varchar(3),getdate(),109))
BEGIN
select Customer.CustomerId as ID, Customer.CustomerName as Name, Customer.Phone as [Phone No], 'UnPaid' as [Pay Status], convert(varchar(3),getdate(),109) as [Month], YEAR(GETDATE()) as [Year]
from Customer inner join Fees on Customer.CustomerId = Fees.CustomerId Where FeeMonth = null

END

Help will be appreciated, thanks.

Aucun commentaire:

Enregistrer un commentaire