SELECT records with NULL value in the column in SQL Server

makumbi
 
on Nov 19, 2022 02:30 AM
441 Views

I am trying to return records with select but it is not returnning an

account serialno ledgerkey bookcode bookname author category datetaken markreturned names datereturned particulars duedate d2 Dout

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 ledger WHERE account = '06-00008' and ISNULL(Category,'') = ''  Or (category IS NOT NULL) order by Datereturned Desc

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
PrinceG
 
on Nov 19, 2022 03:14 AM
on Nov 19, 2022 03:16 AM

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