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 adding columns

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2009-12-18 : 12:14:11
I'm getting incorrect syntax near 'sum'

ALTER PROCEDURE [dbo].[GetAreaWeek] --'c', '01'
@Region_LTR varchar (1),
@Area char(2)

As
SET NOCOUNT ON
Select
Case
when sort = 'x' then 'Area ' + right(Region_LTR,1)
else Region_LTR
end AS reg1
,
[Perc Received] = Case
when co = 0 then '0'
when cr = 0 then '0'
else convert (varchar,(cr * 100/co * 100)/100) end + '%',

Ans,
[Perc Ans] = Case
when cr = 0 then '0'
when Ans = 0 then '0'
else convert(varchar,(ans * 100/cr * 100)/100) end + '%',

OverFlow,
[Perc Overflow] = Case
when cr = 0 then '0'
when overflow = 0 then '0'
else convert(varchar,(overflow * 100/cr * 100)/100) end + '%',

Aband,
[Perc Aband] = Case
when cr = 0 then '0'
when Aband = 0 then '0'
else convert(varchar,(Aband * 100/cr * 100)/100) end + '%',

Busy,
[Perc Busy] = Case
when co = 0 then '0'
when Busy = 0 then '0'
else convert(varchar,(Busy * 100/co * 100)/100) end + '%'


select sum(CO) as CO
sum(CR) as CR,
sum(Ans) as Ans,
sum(Overflow) as OverFlow,
sum(Aband) as Aband,
sum(Busy) as Busy,
convert(varchar,dowrdate,1) as dowrdate
from TSRPtotals
where (sort='1') or (sort = @Region_LTR) or (Region_LTR= @Region_LTR and area = @Area and sort = 'x' and doc='000')
or (Region_LTR= @Region_LTR and area = @Area and sort = 'z')

DP978
Constraint Violating Yak Guru

269 Posts

Posted - 2009-12-18 : 13:17:38
select sum(CO) as CO,
sum(CR) as CR,
sum(Ans) as Ans,
sum(Overflow) as OverFlow,
sum(Aband) as Aband,
sum(Busy) as Busy,
convert(varchar,dowrdate,1) as dowrdate
from TSRPtotals
where (sort='1') or (sort = @Region_LTR) or (Region_LTR= @Region_LTR and area = @Area and sort = 'x' and doc='000')
or (Region_LTR= @Region_LTR and area = @Area and sort = 'z')
Go to Top of Page
   

- Advertisement -