Solved

Sql server 2005 count function

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article I will describe the Backup & Restore 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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

12 Experts available now in Live!

Get 1:1 Help Now