Solved

Sql server 2005 count function

Posted on 2012-03-27
2
363 Views
Last Modified: 2012-03-27
Hi,
 I have a query like below

select count(*) from(
select examdate,patient_no from exams where requestedby=73201 and
examdate>='01/02/1988' and examdate<='05/01/1988'
and (height is not null or height!='') group by examdate,patient_no)

but when I execute I am getting the error which is shown below
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near ')'.

Please let me know how can I do it.

Thank you
0
Comment
Question by:Sthokala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 32

Accepted Solution

by:
bhess1 earned 500 total points
ID: 37772589
You need to name your derived table.  This syntax should work for you:

select count(*) from(
	select 
		examdate,
		patient_no 
	from exams 
	where requestedby=73201 
		and examdate>='01/02/1988' 
		and examdate<='05/01/1988' 
		and (height is not null or height!='') 
	group by examdate,patient_no) AS SourceQuery

Open in new window

0
 

Author Comment

by:Sthokala
ID: 37772598
Thank you for the quick answer.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sql Query join multiple table and distinct records 7 32
Caste datetime 2 69
Help with simplifying SQL 6 54
SQL Server - Set Field Values ito Zero Based on Related Table 4 44
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question