Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COUNT(1) , returns zero records?

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi

I'm struggling with why my SQL command won't work.

If i run
Code:
SELECT FirstName + ' ' + LastName AS Adviser,CompanyName FROM Business_Register LEFT JOIN Members ON Business_Register.Adv_MemNo = Members.ID WHERE  Adv_MemNo like 'n%'

I get 23140 records!

However, as soon as I try to group and count with..
Code:
SELECT FirstName + ' ' + LastName AS Adviser,CompanyName,COUNT(1) AS Cases FROM Business_Register LEFT JOIN Members ON Business_Register.Adv_MemNo = Members.ID WHERE Adv_MemNo like 'n%'  GROUP BY Adviser,CompanyName

I get 0 records, what am i doing wrong?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
It's OK, worked it out , I cannot group by adviser, I have to group using the concatenation.

---------------------------------------------------
Word of warning , NEVER, EVER user the DBI module in PERL with MS SQL no matter what anyone tells you, it sucks, doesn't work properly and doesn't report errors be them syntax or otherwise!

Use WIN32::ODBC everytime!



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Which table is Adv_MemNo in?

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Just as an example, I replaced the DBI module with Win32::ODBC and now I get errors such as
xxxxx is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

Which DBI doesn't seem to produce?



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top