Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Retrieve NULL or MAX()?
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01022042
Message ID:
01022121
Vues:
13
>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--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform