Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Some values return NULL

Author  Topic 

kcarbone1970
Yak Posting Veteran

52 Posts

Posted - 2013-10-08 : 14:16:24
I need my query to return either a yes or no value, when an individual has no data this query will return a NULL value, I need it to say No...Any help greatly appreciated


SELECT MIN(CASE WHEN (SD IS NOT NULL) AND (ED IS NULL) AND (CD NOT BETWEEN 600 AND 699) THEN 'Yes' ELSE 'No' END)
AS [On Target?]
FROM ACT
WHERE (PID = @ID)


IT Consultation for Education Institutions

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-10-08 : 14:27:58
You could use COALESCE (assuming the logic is correct)
SELECT  COALESCE(MIN(CASE WHEN (SD IS NOT NULL) AND (ED IS NULL) AND (CD NOT BETWEEN 600 AND 699) THEN 'Yes' ELSE 'No' END),'No')
AS [On Target?]
FROM ACT
WHERE (PID = @ID)
Go to Top of Page

kcarbone1970
Yak Posting Veteran

52 Posts

Posted - 2013-10-09 : 19:48:31
Cool thanks so much!!

IT Consultation for Education Institutions
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-10-10 : 07:55:41
It is because aggregate functions always return at least a row even if there is no data in the table.

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -