Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help with completed sql call
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00616796
Message ID:
00616938
Vues:
10
Venelina

Here is what I have got worked up in the query anaylizer:
declare @ttDate1 datetime
declare @ttDate2 datetime

set @ttDate1='02/08/2002 00:00:00'
set @ttDate2='02/08/2002 23:59:00'

SELECT  dbo.meetproc.dcode, 
        avg(datediff(mi,meetings.enteror,meetings.exitor)) as timeused,
        count(dbo.meetproc.dcode) as proccnt,
	(select avg(cocasedata.itemunitcost * coCaseData.ActualQty)
		FROM dbo.meetings INNER JOIN
                dbo.meetproc ON dbo.meetings.meetingnumber = dbo.meetproc.meetingnumber INNER JOIN
                dbo.cocasedata ON dbo.meetings.meetingnumber = dbo.cocasedata.meetingnumber
		where meetings.begintime between @ttDate1 and @ttDate2 
		AND meetproc.dcode = meetproc.dcode) as avgResCost
FROM   dbo.meetings INNER JOIN
       dbo.meetproc ON dbo.meetings.meetingnumber = dbo.meetproc.meetingnumber
where meetings.begintime between @ttDate1 and @ttDate2
group by dcode
It almost works (to my amazing surprise), with the exception that the avgResCost returns the same value for every record returned. I pretty sure this is because of the where clause Meetproc.dcode=meetproc.dcode. I know I need to reference the tables with an alias, but I'm not sure of the right way to do this. Can you help
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform