Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can this be done with a JOIN?
Message
 
 
À
12/04/2007 14:51:56
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01215163
Message ID:
01215171
Vues:
12
>I have two tables - we'll call them Customer and Bill. A customer can have zero or many bills, and it is linked by the CustomerID. What I want to do is pull a customer by CustomerID and also pull their last bill only if it is within 30 days old. If there isn't a bill that fits that criteria, I want null value.
>
>Can I do this with a JOIN? Anybody have any advice on how to do the filtering in the JOIN statement?

... or this one
SELECT * 
	FROM Customer c
	LEFT JOIN Bill b ON b.CustomerID = c.CustomerID  
		AND  Billdate = (SELECT MAX(BillDate) FROM Bill b2 
					WHERE b2.CustomerID = b.CustomerID  
						AND BillDate >= DATEADD(dd, -30, getdate) )
	WHERE CustomerID = @CustomerID
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform