Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
IIF(,,) in an SQL Server SQL Statement
Message
De
18/04/2000 19:40:20
 
 
À
18/04/2000 17:08:15
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00360347
Message ID:
00361102
Vues:
23
SQL Server only allows columns to appear in the column list if they are within an aggregate function or in the GROUP BY column list. If you think about it, it makes sense. Consider the following:
CREATE TABLE countrydata (
 city varchar(20),
 state varchar(2), 
 population integer)

SELECT city, state, MAX(population)
FROM countrydata
GROUP BY state
What value should SQL Server return for city? Within this table there will probably be more than one city for each state. VFP picks a value. I don't know of there's any reasoning to the value that's chosen nor would I want to rely on it. SQL Server (and the ANSI standard I believe) take the easy approach and just don't allow it.

BTW, this query should return all the info that you thought the above query would (I hope, it's completely off the cuff <s>)
SELECT city, state, population
FROM countrydata
WHERE population = (
 SELECT MAX(population)
 FROM countrydata cd
 WHERE state = countrydata.state)
-Mike
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform