Solved

Sql server 2005 count function

Posted on 2012-03-27
2
368 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:
Brendt Hess 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

622 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