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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assistance with Stored Procedure

Status
Not open for further replies.

nc297

Programmer
Apr 7, 2010
162
US
I'm back...

I fixed this stored procedure the way George taught me but now I want to add some more code. I'm summing columns from the temp table and want those outputs to go into the T2counts table. Where would I place this bit of code in the below procedure?

(SELECT t.doc, SUM(t.pendinfo1 + t.pendinfo2 + t.pendinfo3) AS pendinfo
FROM (SELECT *
FROM #temppd) t
GROUP BY t.doc)d
ON n.doc = d.doc

LEFT JOIN
(SELECT t.doc, sum(t. PendFOover1 + t.PendFOover2 + t.PendFOover3) as pendfo300
FROM (SELECT *
FROM #temppd) t
GROUP BY t.doc)f
ON n.doc = f.doc
left join
(SELECT t.doc, SUM(t.foddspend1 + t.foddspend2 + t.foddspend3 + t.pendinDDS1) AS totalpendover300
FROM (SELECT *
FROM #temppd) t
GROUP BY t.doc)g
on n.doc= g.doc

left join
(SELECT t.doc, SUM(t.foddspend4 + t.foddspend5 + t.foddspend6 + t.pendinDDS2) AS totalpendover350
FROM (SELECT *
FROM #temppd) t
GROUP BY t.doc)h
ON n.doc = h.doc
left join
(SELECT t.doc, SUM(t.foddspend7 + t.foddspend8 + t.foddspend9 + t.pendinDDS3) AS totalpendover399
FROM (SELECT *
FROM #temppd) t
GROUP BY t.doc)j
ON n.doc = j.doc

left join
(SELECT t.doc, SUM(t.foddspend10 + t.foddspend11 + t.foddspend12 + t.pendinDDS4) AS totalpendover400
FROM (SELECT *
FROM #temppd) t
GROUP BY t.doc)k
ON n.doc = k.doc


This is the orginal query I want to add the above code to this query.

Truncate Table T2Counts
insert T2Counts

select n.doc,
ISNULL(PendinDDS, 0) AS PendinDDS,
ISNULL(PendinPSC,0) AS PendinPSC,
ISNULL(PendDDSover300,0) AS PendDDSover300,
ISNULL(Pendinfo,0) AS Pendinfo,
ISNULL(Pendfo300,0) AS Pendfo300,
ISNULL(totalpendover300,0) AS totalpendover300,
ISNULL(totalpendover350, 0) AS totalpendover350,
ISNULL(totalpendover399, 0) AS totalpendover399,
ISNULL(totalpendover400, 0) AS totalpendover400

from natdocfile n
left join
----pendinDDS
(Select t.doc,
ISNULL(COUNT(Case When DIB_MVT_TYP='R'
and LEFT(Org_Id,1) IN ('R','S','V')
and People.ssn is not null
Then t.clmn End ), 0) as PendinDDS,
MAX(Case When DIB_MVT_TYP='R'
and LEFT(Org_Id,1) IN ('R','S','V')
and People.ssn is not null
Then dib_mvt_seq_num End) as MaxSeq1,

--pending in the PSC
ISNULL(count(Case When DIB_MVT_TYP='R'
and left (org_id, 1) IN ('P')
and People.ssn is not null
Then t.clmn End), 0) as PendinPSC,
Max(case When DIB_MVT_TYP='R'
and left (org_id, 1) IN ('P')
and People.ssn is not null
Then dib_mvt_seq_num End) as MaxSeq2,

--pendddsover300
ISNULL(Count(Case when DIB_MVT_TYP='R'
and (org_id like '[RS]%')
and People.ssn is not null
Then t.clmn End), 0) as PendDDSover300,
Max(Case when DIB_MVT_TYP='R'
and (org_id like '[RS]%')
and People.ssn is not null
Then dib_mvt_seq_num End) as MaxSeq3

from t2dibpend t
Left Join seb2a21.specnew.dbo.people as People
On t.clmn = People.ssn
and People.completedt is null
group by t.doc) a
on n.doc = a.doc


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top