Thursday, March 22, 2012

Count (Distinct ?

Owen Mortensen wrote:
> SQL Server 2000
> Why can't I do this:
> Count (Distinct FName, LName)
> ?
> TIA,
> Owen
Do:
SELECT COUNT(*)
FROM
(SELECT DISTINCT fname, lname
FROM some_table
WHERE fname IS NOT NULL
AND lname IS NOT NULL) AS T;
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--AHHH! That will do it!
Thanks!
Owen
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1142019969.039573.5400@.v46g2000cwv.googlegroups.com...
> Owen Mortensen wrote:
> Do:
> SELECT COUNT(*)
> FROM
> (SELECT DISTINCT fname, lname
> FROM some_table
> WHERE fname IS NOT NULL
> AND lname IS NOT NULL) AS T;
> --
> David Portas, SQL Server MVP
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>

No comments:

Post a Comment