Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Multiple table
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

179 Posts

Posted - 11/09/2006 :  12:38:13  Show Profile  Reply with Quote
Hi all,

I have two table,
one is C20_Messages and second one is Ports.
Here want to get the count of records if the status of Ports_ID = 1

Then I wrote the query like this, but showing error

SELECT C20_messages.Port_ID, Ports.status, COUNT(C20_messages.*) AS Sum FROM C20_messages, Ports where datepart(year,C20_messages.Msg_Time) = '2006' and C20_Messages.Port_ID = Ports.ID and Ports.Status = 1 GROUP BY C20_Messages.Port_ID

pls help me


Flowing Fount of Yak Knowledge

1837 Posts

Posted - 11/09/2006 :  13:08:58  Show Profile  Reply with Quote
If you want to have Ports.status in the select list you'll have to put it in your GROUP BY. Otherwise if you don't really need it then remove it from the select list. And you can just use COUNT(*).
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2019 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000