Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
IIF(,,) in an SQL Server SQL Statement
Message
From
18/04/2000 19:40:20
 
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00360347
Message ID:
00361102
Views:
24
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform