Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 18th, 2005, 03:15 AM
Authorized User
 
Join Date: Aug 2004
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default Query

Hello,

  I am retrieving the data from two tables.
Emp:
----
empid empname basic

dailydetails:
--------------
indexno empid qty target trdate piecerate nohours


I want to get the details from these tables.
The second table contain many records for the same empid on the same date. Like that, for each empid i want to find, the number of days worked for each employee in the specific month and year.

Suppose, empid: 0101 month:Jan Year: 2005

i want to find the number of days he worked. How can i find???

i need to use two queries???/




 
Old February 18th, 2005, 06:57 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran
Default

hi,
this is the basic idea
SELECT dailydetails.*, Emp.* FROM dailydetails INNER JOIN Emp ON dailydetails.empid = Emp.empid where Emp.empid=0101;

but you have to write two commant

select and select count

please date type for the perticular search field

surendran
(Anything is Possible)
 
Old February 18th, 2005, 10:06 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Plese provide some sample data and exactly how you like your results. for e.g. trdate is this a datetime field? etc.

 
Old February 18th, 2005, 09:42 PM
Authorized User
 
Join Date: Aug 2004
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

  Thanx for the replies.

Sample Data:

Emp:
0101 AAAA 260
0102 BBBB 260
0103 CCCC 280

dailydetails:
index empid qty target trdate piecerate nohours
1 0101 200 250 01-Jan-2005 Y 8
2 0101 250 260 01-Jan-2005 Y 8
3 0101 400 500 02-Jan-2005 Y 8
4 0101 350 300 02-Jan-2005 Y 8
5 0101 450 600 02-Jan-2005 Y 8
6 0102 240 250 01-Jan-2005 Y 8
7 0102 500 550 01-Jan-2005 Y 8
8 0102 350 350 03-Jan-2005 Y 8
9 0102 300 250 03-Jan-2005 Y 8
10 0102 350 380 04-Jan-2005 Y 8
...

My report should look like...

emp.empid emp.empname emp.basic nodays
-------------------------------------------
0101 AAAA 260 2
0102 BBBB 260 3

....


thanks

 
Old February 19th, 2005, 10:09 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

SELECT emp.empname, emp.basic, Q.empid, count(q.trdate) AS NoOfDays
FROM [SELECT empid, trdate
FROM dailydetails
GROUP BY empid, trdate ]. AS Q INNER JOIN Emp ON emp.empid = Q.empid
GROUP BY Q.Empid, emp.empname, emp.basic;


 
Old February 21st, 2005, 04:20 AM
Authorized User
 
Join Date: Aug 2004
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Hello,

   Sorry, its giving error "Can not find table "select empid,trdate..."



 
Old February 21st, 2005, 04:50 AM
Registered User
 
Join Date: Feb 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

SELECT emp.empname, emp.basic, Q.empid, count(q.trdate) AS NoOfDays
FROM [SELECT dailydetails.empid, dailydetails.trdate
FROM dailydetails
GROUP BY dailydetails.empid, dailydetails.trdate ]. AS Q INNER JOIN Emp ON emp.empid = Q.empid
GROUP BY Q.Empid, emp.empname, emp.basic;







Similar Threads
Thread Thread Starter Forum Replies Last Post
Output Query to txt file from SQL Query everest SQL Server 2005 4 November 22nd, 2007 01:49 AM
how to make a query from an existing query raport SQL Language 3 November 13th, 2006 08:59 PM
I solved insert query.now see this Update Query. [email protected] VB.NET 2002/2003 Basics 2 September 21st, 2006 12:48 AM
Syntax error in query. Incomplete query clause. dispickle ADO.NET 3 April 16th, 2004 01:04 PM
Error on Make-Table Query In Union Query rylemer Access 1 August 20th, 2003 07:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.