Solved

Sql server 2005 count function

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Getting the 3 middle digits 4 37
SQL Encryption question 2 56
CONVERT date time to a different time zone. 2 55
TSQL mapping detailed records to group records 9 52
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…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

809 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