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)
 Incorrect syntax near ')'.

Author  Topic 

chedderslam
Posting Yak Master

223 Posts

Posted - 2009-04-01 : 12:59:56
Can't figure out where I am wrong in this query. The sub select works fine by itself, but trying to select the aggregate breaks it...


select sum(num_quotes) as total_quotes, sum(num_errors) as total_errors from
(
select hour, ( case
when ptime <= 1000 then 1
when ptime <= 3000 then 3
when ptime <= 5000 then 5
when ptime <= 10000 then 10
when ptime <= 15000 then 15
when ptime <= 20000 then 20
when ptime <= 25000 then 25
when ptime <=30000 then 30
when ptime <=40000 then 40
else 1000 end ) as under_seconds
,count(*) as num_quotes,
sum(error) as num_errors from (
select pos_id,
datediff(ms,min(entry_date),max(entry_date)) as ptime,
min(entry_date) as start,
max(entry_date) as finish,
max(case when entry_data like '%<MsgStatusCd>Error</MsgStatusCd>%' then 1 else 0 end) as error,
max(datepart(hour,entry_date)) as hour
from pos_log (nolock)
where entry_type in (1,3)
and entry_date between '03/31/09 00:00:00' and '03/31/09 23:59:59'
group by pos_id ) as a
group by hour, ( case
when ptime <= 1000 then 1
when ptime <= 3000 then 3
when ptime <= 5000 then 5
when ptime <= 10000 then 10
when ptime <= 15000 then 15
when ptime <= 20000 then 20
when ptime <= 25000 then 25
when ptime <=30000 then 30
when ptime <=40000 then 40
else 1000 end )
)

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-04-01 : 13:10:27
try to properly intent query while posting for better readability

select
sum(num_quotes) as total_quotes,
sum(num_errors) as total_errors
from
(
select hour,
case
when ptime <= 1000 then 1
when ptime <= 3000 then 3
when ptime <= 5000 then 5
when ptime <= 10000 then 10
when ptime <= 15000 then 15
when ptime <= 20000 then 20
when ptime <= 25000 then 25
when ptime <=30000 then 30
when ptime <=40000 then 40
else 1000
end as under_seconds,
count(*) as num_quotes,
sum(error) as num_errors
from (
select pos_id,
datediff(ms,min(entry_date),max(entry_date)) as ptime,
min(entry_date) as start,
max(entry_date) as finish,
max(case when entry_data like '%<MsgStatusCd>Error</MsgStatusCd>%' then 1 else 0 end) as error,
max(datepart(hour,entry_date)) as hour
from pos_log (nolock)
where entry_type in (1,3)
and entry_date between '03/31/09 00:00:00'
and '03/31/09 23:59:59'
group by pos_id
) as a
group by hour,
case
when ptime <= 1000 then 1
when ptime <= 3000 then 3
when ptime <= 5000 then 5
when ptime <= 10000 then 10
when ptime <= 15000 then 15
when ptime <= 20000 then 20
when ptime <= 25000 then 25
when ptime <=30000 then 30
when ptime <=40000 then 40
else 1000
end
)r
Go to Top of Page

chedderslam
Posting Yak Master

223 Posts

Posted - 2009-04-01 : 14:14:54
Sorry. I will do so in the future.
Go to Top of Page
   

- Advertisement -