Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Query

Status
Not open for further replies.

annub

Programmer
Apr 23, 2003
33
US
I am doing something like this in my select statment
Query -1
SELECT Indirectlabcode.Labcode, emplhrdtltest.shiftnumber, emplhrdtltest.jobnumber, SUM(emplhrdtltest.totaltime) AS Expr1, emplhrdtltest.[date]
FROM Indirectlabcode INNER JOIN
emplhrdtltest ON Indirectlabcode.Labcode = emplhrdtltest.labcode
GROUP BY Indirectlabcode.Labcode, emplhrdtltest.shiftnumber, emplhrdtltest.jobnumber, emplhrdtltest.[date]
HAVING (emplhrdtltest.[date] = '02192004')

result i get is
******************************************************
Result -1
16 1 000000 32.5 02192004
60 1 000000 16 02192004
68 1 000000 33 02192004
69 1 000000 16 02192004
If i do
Query -2
----------------------------------------------------------
SELECT Indirectlabcode.Labcode, emplhrdtltest.shiftnumber, emplhrdtltest.jobnumber, SUM(emplhrdtltest.totaltime) AS Expr1, emplhrdtltest.[date],
emplhrdtltest.totaltime * 15 AS Expr2
FROM Indirectlabcode INNER JOIN
emplhrdtltest ON Indirectlabcode.Labcode = emplhrdtltest.labcode
GROUP BY Indirectlabcode.Labcode, emplhrdtltest.shiftnumber, emplhrdtltest.jobnumber, emplhrdtltest.[date], emplhrdtltest.totaltime * 15
HAVING (emplhrdtltest.[date] = '02192004')
-----------------------------------------------------
i get
Result -2
16 1 000000 24 02192004 120
16 1 000000 8.5 02192004 127.5
60 1 000000 16 02192004 120
68 1 000000 33 02192004 123.75
69 1 000000 16 02192004 120

I want result -1 when i run query-2 for some reason i get 16 labcode twice not sure why . I checked my tables if i need to some result should have as result -1

Thanks

 
It's because you are grouping by
Code:
emplhrdtltest.totaltime * 15
.
If you want to get the totaltime by 15 then use
Code:
 SUM(emplhrdtltest.totaltime)* 15
in your select list and don't group by totaltime.

Durkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top