Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Retrieve NULL or MAX()?
Message
 
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01022042
Message ID:
01022121
Views:
15
>I need to return a query result from a datetime field in a child table that either returns NULL if "any" record that matches the condition is NULL or return MAX() if all matching records have non-null values.
>
>To give you an example, if a person is given list of 10 tasks with a separate deadline date, I need a query that returns NULL date if any of the 10 task is not completed OR MAX() date if all tasks have been completed.
>
>Anyone have a simple query statement for this? Thanks.
SELECT CASE WHEN COUNT(*) = COUNT(mydate) THEN 	MAX(mydate) 
	ELSE CAST(NULL AS datetime) END AS maxdate
	FROM mytable
        WHERE < Whetever Condition >
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform