I have this problem in my SQL code:
I will only show my suggestion WHERE, because it is a little long, this is it:
where
((@account_status = 1027 AND a.AccountStatus = 1027 AND a.FolioNo =
@folio_no AND b.ReservationNo = @reservation_id)) OR
((@account_status = 1026 AND a.AccountStatus = 1026 AND a.FolioNo =
@folio_no AND b.ReservationNo = @reservation_id)) OR
((@account_status = 1025 AND a.AccountStatus = 1025 AND @trans_code = 1 AND
a.AccountStatementTransCode = 1 AND b.FolioNo = @folio_no AND
b.ReservationNo = @reservation_id)) OR
((@account_status = 1025 AND a.AccountStatus = 1025 AND @trans_code != 1
AND a.AccountStatementTransCode != 1 AND b.FolioNo = @folio_no AND
b.ReservationNo = @reservation_id)) OR
((a.FolioNo = @folio_no AND b.ReservationNo = @reservation_id AND
@trans_code = 2 AND a.AccountStatementTransCode = 2 AND
case
when @sub_category = 14 then i.category_id is null
else i.category_id = @sub_category
end )) OR
((a.FolioNo = @folio_no AND b.ReservationNo = @reservation_id AND
@trans_code = 3 AND a.AccountStatementTransCode = 3 AND i.category_id =
@sub_category)) OR
((a.FolioNo = @folio_no AND b.ReservationNo = @reservation_id AND
@trans_code = 4 AND a.AccountStatementTransCode = 4 AND i.category_id =
@sub_category)) OR
((a.FolioNo = @folio_no AND b.ReservationNo = @reservation_id AND
@trans_code = 5 AND a.AccountStatementTransCode = 5 AND i.category_id =
@sub_category)) OR
((a.FolioNo = @folio_no AND b.ReservationNo = @reservation_id AND
@trans_code = 6 AND a.AccountStatementTransCode = 6 AND i.category_id =
@sub_category))
I want if input @sub_category = 14, then it will return a category with values NULL, otherwise it will return values @sub_category. How can i do this?
source
share