Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with SQL query

Author  Topic 

dandah
Starting Member

1 Post

Posted - 2012-02-27 : 14:23:42
I have a query that counts nulls in a large DB through PHP. It works but tends to be taxing. Sometimes it times out. Can anyone tell me if there is a more efficient method to do this query?

SELECT COUNT (STUDY.PATIENT_ID) AS TOTAL
FROM STUDY
WHERE ((STUDY.PATIENT_ID LIKE '%ns001')
OR (STUDY.PATIENT_ID LIKE '%NS001'))
AND (STUDY.GLOBAL_ID IS NULL)
AND (STUDY.DATE_TIME_VERIFIED > '0')
GROUP BY STUDY.GLOBAL_ID

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2012-02-27 : 14:30:49
Any Indexes? Statistics up to date? I take it the collation is set to case sensitive. Yuck.

Not sure how you get a return with grouping by global_ID instead of Patient_ID.(i am guessing typo).

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -