Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Get the count using sql query on sql server  2005

Posted on 2009-04-21
5
Medium Priority
?
323 Views
Last Modified: 2012-05-06
Please see the below query. please tell me how to get count using below uery.

thanks
(SELECT DISTINCT   Title, Label, Date
FROM [fnGetTotalDocs]() As TotalDocs
AND not exists
(SELECT Title, Label, Date
       FROM [ReadDocs] As ReadDocs
and TotalDocs.Title=ReadDocs.Title
)
order by Date

Open in new window

0
Comment
Question by:Saroj13
  • 2
  • 2
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24197885
the query, as you showed, is incomplete and incorrect.
apart from that, what should the end-result look like?
0
 

Author Comment

by:Saroj13
ID: 24197902
This query is the complete one. I want to dispaly the #
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24198061
I cannot believe this is the full query, at least not for sql 2005:
§  there is no WHERE (just AND alone is a syntax error)
§ no subquery alias (another syntax error)
§  the [] around Date as reserved keyword for column name is missing (might return wrong results)

anyhow:
>I want to dispaly the #

# of what? in regards to the rows returned, the total #?
or per "group" of Title?
or per "group" of Title + label?

please provide sample data with the matching output requested to clarify the request.
0
 
LVL 1

Accepted Solution

by:
sangalanga earned 2000 total points
ID: 24198092
SELECT COUNT(DISTINCT   Title)
FROM [fnGetTotalDocs]() As TotalDocs
AND not exists
(SELECT Title, Label, Date
       FROM [ReadDocs] As ReadDocs
and TotalDocs.Title=ReadDocs.Title
)
order by Date
This will give you a count.

Including label and date will give an aggregate error. Try grouping them first.
0
 

Author Comment

by:Saroj13
ID: 24198200
here is the updated query

I am getting teh TotalDocs and Read Docs . Displaying those are not in ReadDocs.
I want the count.
SELECT DISTINCT   Title, Label, DateStamp
FROM [fnGetTotalDocs]() As TotalDocs
WHERE
Title != ''
AND not exists
(SELECT Title ,Label, UserID, DateTimeStamp
       FROM [ReadDocs] As ReadDocs
where UserID='abc'
and TotalDocs.Title =ReadDocs.Title
)
order by DateStamp 

Open in new window

0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

580 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