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.
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 appreciatedSELECT 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 ACTWHERE (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 ACTWHERE (PID = @ID) |
|
|
kcarbone1970
Yak Posting Veteran
52 Posts |
Posted - 2013-10-09 : 19:48:31
|
Cool thanks so much!!IT Consultation for Education Institutions |
|
|
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.MadhivananFailing to plan is Planning to fail |
|
|
|
|
|