|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Stuck on this query
I need the results from the following query to be with the results of the second query. Any ideas?
Code:
SELECT
PR.WBS1, PR.WBS2, PR.WBS3, PR.Fee, PR.ConsultFee, PR.ReimbAllow, PR.LongName, PR.Name, CL.Name AS CLIENTNAME,
CLAddress.Address2 AS CLIENTADDRESS2, CLAddress.Address3 AS CLIENTADDRESS3, CLAddress.Address4 AS CLIENTADDRESS4,
CFGMain.FirmName, CFGMain.Address1, CFGMain.Address2, CFGMain.Address3, CFGMain.Address4,
Contacts.FirstName + ' ' + Contacts.LastName AS CONTACT, LB.AmtBud, LB.BillBud
FROM PR LEFT OUTER JOIN
Contacts ON PR.ContactID = Contacts.ContactID LEFT OUTER JOIN
CL ON CL.ClientID = PR.ClientID LEFT OUTER JOIN
CLAddress ON CL.ClientID = CLAddress.ClientID LEFT OUTER JOIN
LB ON LB.WBS1 = PR.WBS1 AND PR.WBS2 = LB.WBS2 AND LB.WBS3 = PR.WBS3
CROSS JOIN
CFGMain
Where pr.wbs1 = '001-298' and pr.wbs3 != 'zzz'
and Code:
SELECT * FROM LD WHERE (BilledPeriod = '200408') AND (WBS1 = '001-298') Thanks. |
|
#2
|
|||
|
|||
|
Quote:
Hmmm. Are there some words missing here? Do you mean a join like Code:
SELECT LD.*,
PR.WBS1,
PR.WBS2,
PR.WBS3,
PR.Fee,
PR.ConsultFee,
PR.ReimbAllow,
PR.LongName,
PR.Name,
CL.Name AS CLIENTNAME,
CLAddress.Address2 AS CLIENTADDRESS2,
CLAddress.Address3 AS CLIENTADDRESS3,
CLAddress.Address4 AS CLIENTADDRESS4,
CFGMain.FirmName,
CFGMain.Address1,
CFGMain.Address2,
CFGMain.Address3,
CFGMain.Address4,
Contacts.FirstName + ' ' + Contacts.LastName AS CONTACT,
LB.AmtBud,
LB.BillBud
FROM LD
inner join PR on LD.WBS1 = PR.WBS1
LEFT JOINContacts ON PR.ContactID = contacts.ContactID
LEFT JOIN CL ON CL.ClientID = PR.ClientID
LEFT JOIN CLAddress ON CL.ClientID = CLAddress.ClientID
LEFT JOIN LB ON LB.WBS1 = PR.WBS1
AND PR.WBS2 = LB.WBS2
AND LB.WBS3 = PR.WBS3
CROSS JOIN CFGMain
Where ld.wbs1 = '001-298'
and ld.BilledPeriod = '200408'
and pr.wbs3 <> 'zzz'
explain more otherwise |
|
#3
|
|||
|
|||
|
I changed up the query to make it a little more simple.
Basically, I am displaying the results of project code, the amount budgeted for each code, and I need the sum of the billext to be displayed per project code. However, the billext needs to be based on a certain billing period, '200408' if I put that condition is placed I notice that I do not get all of my results. This is what I have now: Code:
SELECT PR.WBS1, PR.WBS2, PR.WBS3, LB.AmtBud, LD.BillExt
FROM PR INNER JOIN
LD ON PR.WBS1 = LD.WBS1 AND LD.WBS2 = PR.WBS2 AND PR.WBS3 = LD.WBS3 LEFT OUTER JOIN
LB ON LB.WBS1 = PR.WBS1 AND LB.WBS2 = PR.WBS2 AND LB.WBS3 = PR.WBS3
WHERE (PR.WBS1 = '001-298') AND (LD.BilledPeriod = '200408')
ORDER BY PR.WBS2, PR.WBS3
All I want is the results from the following query: Code:
SELECT PR.WBS1, PR.WBS2, PR.WBS3, LB.AmtBud
FROM PR LEFT OUTER JOIN
LB ON LB.WBS1 = PR.WBS1 AND LB.WBS2 = PR.WBS2 AND LB.WBS3 = PR.WBS3
WHERE (PR.WBS1 = '001-298') AND (PR.WBS3 <> 'ZZZ')
ORDER BY PR.WBS2, PR.WBS3
with the summation of LD.billExt where LD.billedPeriod = '200408' beside the AmtBud. Even if the AmtBud does not fall within the LD.BillingPeriod Hope I explained this clear enough |
|
#4
|
|||
|
|||
|
Code:
SELECT PR.WBS1, PR.WBS2, PR.WBS3, LB.AmtBud
FROM PR LEFT OUTER JOIN
LB ON LB.WBS1 = PR.WBS1 AND LB.WBS2 = PR.WBS2 AND LB.WBS3 = PR.WBS3
WHERE (PR.WBS1 = '001-298') AND (PR.WBS3 <> 'ZZZ')
ORDER BY PR.WBS2, PR.WBS3
Code:
SELECT PR.WBS1, PR.WBS2, PR.WBS3, SUM(LD.BillExt) AS Expr1
FROM PR LEFT OUTER JOIN
LD ON LD.WBS1 = PR.WBS1 AND PR.WBS2 = LD.WBS2 AND PR.WBS3 = LD.WBS3
WHERE (PR.WBS1 = '001-298') AND (PR.WBS3 <> 'ZZZ') AND (LD.BilledPeriod = '200408')
GROUP BY PR.WBS1, PR.WBS2, PR.WBS3
ORDER BY PR.WBS2, PR.WBS3
Basically all I need to do is create a column in the first query that will include the results of the second query. For Example, WBS1 WBS2 WBS3 AmtBud BillExt 001-298 1217 010 3000 1952.50 001-298 1217 100 4000 <Null> Any suggestions? It is probably some join that I need to perform |
|
#5
|
||||
|
||||
|
Code:
SELECT PR.WBS1
, PR.WBS2
, PR.WBS3
, LB.AmtBud
, ( select SUM(LD.BillExt)
from LD
where WBS1 = PR.WBS1
AND WBS2 = PR.WBS2
AND WBS3 = PR.WBS3
and BilledPeriod = '200408' ) as Expr1
FROM PR
LEFT OUTER
JOIN LB
ON LB.WBS1 = PR.WBS1
AND LB.WBS2 = PR.WBS2
AND LB.WBS3 = PR.WBS3
WHERE (PR.WBS1 = '001-298')
AND (PR.WBS3 <> 'ZZZ')
ORDER
BY PR.WBS2
, PR.WBS3
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Stuck on this query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|