Hi makumbi,
Please refer below updated query.
SQL
CREATE TABLE #BankDetails
(
account VARCHAR(100),
serialno INT,
ledgerkey INT,
bookcode DECIMAL,
bookname VARCHAR(100),
author VARCHAR(100),
category VARCHAR(100),
datetaken VARCHAR(100),
markreturned INT,
names VARCHAR(100),
datereturned VARCHAR(100),
particulars VARCHAR(100),
duedate VARCHAR(100),
d2 VARCHAR(100),
Dout VARCHAR(100)
)
INSERT INTO #BankDetails VALUES('06-00002',0001,1,567.89, 'GOOD NEWS BIBLE','UNITED BIBLE SOCIETY',
'Returned','2022-11-19 11:50:23.000',1,'AMONGIN PHOEBE',
'2022-11-19 11:50:54.000',NULL,NULL,NULL,NULL)
SELECT account,serialno,ledgerkey,bookcode,bookname,author,category,datetaken,markreturned,names,datereturned,particulars,duedate,d2,Dout
FROM #BankDetails
WHERE account = '06-00002' and (ISNULL(Category,'') = '' Or category IS NOT NULL)
order by Datereturned Desc
DROP TABLE #BankDetails
Output
account |
serialno |
ledgerkey |
bookcode |
bookname |
author |
category |
datetaken |
markreturned |
names |
datereturned |
particulars |
duedate |
d2 |
Dout |
06-00002 |
1 |
1 |
568 |
GOOD NEWS BIBLE |
UNITED BIBLE SOCIETY |
Returned |
19-11-2022 11:50 |
1 |
AMONGIN PHOEBE |
19-11-2022 11:50 |
NULL |
NULL |
NULL |
NULL |