Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem with SELECT
Message
De
08/08/2012 11:50:48
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01550073
Message ID:
01550150
Vues:
37
Clip . . .

>I know it's not the most beautiful code around but it seems to work OK unless either of you can tell me I did something really bad.
>
>Thanks for your efforts.

Oops . . . that was the wrong code sample. Here's the correct one. (Too many projects at once.)
select a.element, a.subelement, a.elementnum, a.Lead, a.TotalCost, a.OtherFunds, a.Budget, a.Period,
convert(integer,isnull(SUM(l.amount),0)/1000) as expended, 00000000 as programmed
into #Temp
from RTA_Elements a
left join TIP_Projects b on a.ElementNum = convert(integer,substring(b.RtaID,5,2))
left join TIP_Ledger l on b.TipID = l.tipid and l.Fundtype = 'RTA'
group by a.element, a.subelement, a.elementnum, a.Lead, a.TotalCost, a.OtherFunds, a.Budget, a.Period 
order by elementnum

select a.element, a.subelement, a.elementnum, a.Lead, a.TotalCost, a.OtherFunds, a.Budget, a.Period,
convert(integer,isnull(SUM(p.amount),0)) as programmed
into #Temp2
from RTA_Elements a
left join TIP_Projects b on a.ElementNum = convert(integer,substring(b.RtaID,5,2))
left join TIP_ApprovedFunding p on b.TipID = p.tipid and p.Fundtype = 'RTA'
group by a.element, a.subelement, a.elementnum, a.Lead, a.TotalCost, a.OtherFunds, a.Budget, a.Period 
order by elementnum

update #Temp set programmed = (SELECT programmed from #Temp2 where #Temp.ElementNum = #Temp2.ElementNum)

select * FROM #Temp
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform