Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need help putting procedure together

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2009-05-22 : 08:46:18
I wrote two separate stored procedures and now need them both joined. They are both coming from different tables. I tried a Union after the first statement but it's not working. Here are the tables:

ClearedDiary: PendingDiarySDW:
Doc Doc
totmet totovrSDW
totclr totpndSDW
weekdat totpnd
dowrdat weekdat
dowrdat

Here's the two stored procedures.
ALTER PROCEDURE [dbo].[offClearedAreaDist]

@Area char(2),
@Period char(1),
@BgnDt datetime,
@EndDt datetime
As
If @period = 'w'
begin
Select area, dist, sum(totmet) as totm, sum(totclr) as totc,
"perc"=
Case
When sum(totclr) = 0 then 0
When sum(totclr) = 0 then 0
Else
(convert(decimal(6,2),((((sum(totmet)) * 1.00) / sum(totclr)) * 100)))
End
From ClearedDiary c inner join dbo.NatDocFile n on c.doc = n.doc
Where Area = @Area and Weekdat = @BgnDt
group by area,dist
order by dist
end
Else
begin
Select area, dist, sum(totmet) as totm, sum(totclr) as totc,
"perc"=
Case
When sum(totclr) = 0 then 0
When sum(totclr) = 0 then 0
Else
(convert(decimal(6,2),((((sum(totmet)) * 1.00) / sum(totclr)) * 100)))
End
From ClearedDiary c inner join dbo.NatDocFile n on c.doc = n.doc
Where Area = @Area and Weekdat >= @BgnDt and Weekdat <= @BgnDt
group by area,dist
order by dist

end


Select area, dist, sum(totovrSDW) as totovrSDW, sum(totpndSDW) as totpndSDW,
sum(totovr) as totovr, sum(totpnd) as totpnd
From PendingDiarySDW p inner join dbo.NatDocFile n on p.doc = n.doc
Where Area = @Area and Weekdat = @BgnDt
group by area,dist
order by dist








JJ297
Aged Yak Warrior

940 Posts

Posted - 2009-05-22 : 09:38:42
Never mind I put two gridviews into a table and calling them that way. Works for me.
Go to Top of Page
   

- Advertisement -