Solved

Sql server 2005 count function

Posted on 2012-03-27
2
355 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
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

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

Suggested Solutions

Title # Comments Views Activity
spx for moving values to new table 5 70
How to PARSE a text field that is delimited by '~' character? 3 53
passing parameter in sql procedure 9 56
Query 14 54
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

948 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now