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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Group BY - Error Msg

Author  Topic 

Steve95
Starting Member

19 Posts

Posted - 2006-12-06 : 06:17:34
Hi All

iam fairly new to SQL Server and am using SQL server 2005, QA.

I have written the following query but keep getting an error msg

select *
from dbo.domlog
WHERE Database_name like '%Elite%' or Database_name like '%WUR%' or Database_name like '%ruf%'
Group By Database_name

error msg:
Column 'dbo.domlog.lDate' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

Please can you help.....

Also is their an easier way to write like = WUR, Elite, ruf instead me typing out the db name everytime?

Many Thanks in advance...

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-06 : 06:26:51
What are you trying to accomplish?
Try this
select		Database_name,
count(*)
from dbo.domlog
WHERE Database_name like '%Elite%'
or Database_name like '%WUR%'
or Database_name like '%ruf%'
Group By Database_name


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-12-06 : 06:30:16
Why need to GROUP BY? to avoid duplicates?

SELECT DISTINCT Database_name
FROM dbo.domlog
WHERE Database_name like '%Elite%'
or Database_name like '%WUR%'
or Database_name like '%ruf%'


Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page
   

- Advertisement -