Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: RE: count..correction


Message #1 by frazerg@t... on Tue, 9 Apr 2002 06:11:00
SiteManager
If we take the customers table from northwind and run 

Select Count(Distinct CustomerID) from dbo.Customers

It will work as there is only one column being selected

But if we run 

Select Count(Distinct CustomerID,CompanyName) from dbo.Customers

we get this message
Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near ','.

because there are two columns!
If we change this to one column it will work
Select Count(Distinct CustomerID+CompanyName) from dbo.Customers

Regards 


Greg Frazer

> IT IS WORKING....

-----Original Message-----
From: frazerg@t... [mailto:frazerg@t...]
Sent: Tuesday, April 09, 2002 6:11 AM
To: sql language
Subject: [sql_language] RE: count..correction



This won't work if the distinct is operating on more than one column

Select Count(*)
from (Select a,b from c
      ) tab

regards

greg Frazer


> This is a multi-part message in MIME format.

------_=_NextPart_001_01C1CEB0.92FD866A
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

SELECT COUNT( DISTINCT a ) FROM C

-----Original Message-----
From: Rui Correia Monteiro [mailto:RCMONTEIRO@m...]
Sent: Monday, March 18, 2002 12:45 PM
To: sql language
Subject: [sql_language] count..correction




sorry, i forgot the count,=20

How can i count the rows.....?=20

	-----Original Message-----=20
From:   Rui Correia Monteiro [SMTP:RCMONTEIRO@m...]=20
Sent:   Segunda-feira, 18 de Mar=E7o de 2002 18:39=20
To:     sql language=20
Subject:        [sql_language] count..=20

	Hi,=20

	Can anybody tell me how can i can the rows of that query:=20

	Select distinct a,b from c=20

	Thanks in advance=20




	---
Change your mail options at http://p2p.wrox.com/manager.asp or
to unsubscribe send a blank email to =20

---=20
Change your mail options at http://p2p.wrox.com/manager.asp or=20
to unsubscribe send a blank email to
=20


------_=_NextPart_001_01C1CEB0.92FD866A
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<TITLE>[sql_language] count..correction</TITLE>

<META content=3D"MSHTML 6.00.2713.1100" name=3DGENERATOR></HEAD>
<BODY>
<DIV><SPAN class=3D062060819-18032002><FONT face=3DArial color=3D#0000ff =
size=3D2>SELECT=20
COUNT( DISTINCT a ) FROM C</FONT></SPAN></DIV>
<BLOCKQUOTE>
  <DIV class=3DOutlookMessageHeader dir=3Dltr align=3Dleft><FONT =
face=3DTahoma=20
  size=3D2>-----Original Message-----<BR><B>From:</B> Rui Correia =
Monteiro=20
  [mailto:RCMONTEIRO@m...]<BR><B>Sent:</B> Monday, March 18, 2002 =
12:45=20
  PM<BR><B>To:</B> sql language<BR><B>Subject:</B> [sql_language]=20
  count..correction<BR><BR></FONT></DIV><BR>
  <P><FONT face=3DArial color=3D#0000ff size=3D2>sorry, i forgot the =
count,=20
</FONT></P>
  <P><FONT face=3DArial color=3D#0000ff size=3D2>How can i count the =
rows.....?</FONT>=20
  </P>
  <UL>
    <P><FONT face=3DArial size=3D1>-----Original Message-----</FONT> =
<BR><B><FONT=20
    face=3DArial size=3D1>From:&nbsp;&nbsp;</FONT></B> <FONT =
face=3DArial size=3D1>Rui=20
    Correia Monteiro [SMTP:RCMONTEIRO@m...]</FONT> <BR><B><FONT =
face=3DArial=20
    size=3D1>Sent:&nbsp;&nbsp;</FONT></B> <FONT face=3DArial =
size=3D1>Segunda-feira,=20
    18 de Mar=E7o de 2002 18:39</FONT> <BR><B><FONT face=3DArial=20
    size=3D1>To:&nbsp;&nbsp;&nbsp;&nbsp;</FONT></B> <FONT face=3DArial =
size=3D1>sql=20
    language</FONT> <BR><B><FONT face=3DArial=20
    =
size=3D1>Subject:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT></B> =
<FONT=20
    face=3DArial size=3D1>[sql_language] count..</FONT> </P>
    <P><FONT face=3DArial size=3D2>Hi,</FONT> </P>
    <P><FONT face=3DArial size=3D2>Can anybody tell me how can i can the =
rows of=20
    that query:</FONT><FONT face=3DArial> </FONT></P>
    <P><FONT face=3DArial size=3D2>Select distinct a,b from =
c</FONT><FONT=20
    face=3DArial> </FONT></P>
    <P><FONT face=3DArial size=3D2>Thanks in advance</FONT><FONT =
face=3DArial>=20
    </FONT></P><BR><BR><BR>
    <P><FONT face=3DArial>---<BR>Change your mail options at <A=20
    href=3D"http://p2p.wrox.com/manager.asp"=20
    target=3D_blank>http://p2p.wrox.com/manager.asp</A> or<BR>to =
unsubscribe send=20
    a blank email to  </FONT></P></UL>--- <BR>Change =
your mail=20
  options at http://p2p.wrox.com/manager.asp or <BR>to unsubscribe send =
a blank=20
  email to  =
</BLOCKQUOTE>
---
<BR>
Change your mail options at http://p2p.wrox.com/manager.asp or
<BR>
to unsubscribe send a blank email to

</BODY></HTML>

------_=_NextPart_001_01C1CEB0.92FD866A--



  Return to Index