Например:
food fee admission fee
------------------------
100 0
0 100
50 50
0 0
Я хочу запрос, который игнорирует 0 (ноль) значений в обоих полях сборов. Поэтому вывод должен быть
100 0
0 100
50 50
Код
WITH cteReports AS
(
SELECT
tblStudentFees.AdmissionFee, tblStudentFees.BankFee,
tblStudentFees.BookFee, tblStudentFees.ClassName, tblStudentFees.Date,
tblStudentFees.DivisionName, tblStudentFees.FoodFee,
tblStudentFees.OtherFee, tblStudentFees.OtherFee2,
tblStudentFees.StationaryFee, tblStudentFees.StudentFeesId,
tblStudentFees.StudentNo, tblStudentFees.Total, tblStudent.Name,
users.Username, tblState.StateName, tblStudent.StateId,
tblStudent.DistrictId, tblStudent.Name AS Expr1,
users.Username AS Expr2, tblStudent.CityName,
tblStudentFees.PaymentType, tblStudentFees.AccountNo,
tblStudent.Study
FROM
tblStudentFees AS tblStudentFees
LEFT OUTER JOIN
tblStudent AS tblStudent ON tblStudent.StudentNo = tblStudentFees.StudentNo
LEFT OUTER JOIN
tblState AS tblState ON tblState.StateId = tblStudent.StateId
LEFT OUTER JOIN
tblUser AS users ON tblStudentFees.InsertBy = users.UserId
WHERE
tblStudentFees.AdmissionFee != 0.00
AND tblStudentFees.FoodFee = 0.00
OR tblStudentFees.AdmissionFee = 0.00
AND tblStudentFees.FoodFee != 0.00
OR tblStudentFees.AdmissionFee!= 0.00
AND tblStudentFees.FoodFee != 0.00
)
SELECT
AdmissionFee, FoodFee, BankFee, BookFee, ClassName,
Date, DivisionName, OtherFee, OtherFee2,
StationaryFee, StudentFeesId, StudentNo, Total,
Name, Username, StateName, StateId, DistrictId,
Expr1, Expr2, CityName, PaymentType, AccountNo
FROM
cteReports
WHERE
CityName LIKE '%' + @SearchTerm + '%'
AND Date >= @dtfrom
AND Date <= @dtTo
AND Study = 'TRUE'