Link to home
Start Free TrialLog in
Avatar of rwheeler23
rwheeler23Flag for United States of America

asked on

SQL Syntax Question update with no temp table

I was wondering if I can write this update statement without having to use a temp table.
In my query, the PA011101 contains the master list of job numbers, PA30101 has timesheets posted against those jobs and the JOBSTSATUS table is where I am trying to aggregate a total of all time per job. I was hoping there was a way to do this without using a temp table.  The query below fails because invalid syntax with the WHERE. Is there anyway to restructure this query to perform the update without having to resort to the use of a temp table?
UPDATE [MDGPWORK].[dbo].[JOBSTATUS]
		SET LABCOSTACT = (
		SELECT SUM(case when PABase_Qty*PAUNITCOST IS NULL THEN 0 ELSE PABase_Qty*PAUNITCOST END)
		FROM PA30101 pat
		INNER JOIN (
			select rtrim(pacontnumber) as pacontnumber
			from PA01101) as proj
		ON pat.paprojnumber = proj.pacontnumber
		GROUP BY pat.paprojnumber
		WHERE [MDGPWORK].[dbo].[JOBSTATUS].JOBNUMBER = pat.paprojnumber

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of musalman
musalman
Flag of Oman image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial