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)
 query error

Author  Topic 

ntn104
Posting Yak Master

175 Posts

Posted - 2008-09-15 : 07:22:01
Hello,

Please look at the below query and tell me why do I got an error on the highlighted line. Thanks very much!

select c.box, sum(c.trans_amt) as amt, c.trans_code, max(c.dln) as dln, c.process_date, c.tc_code
from dba.ctopenmo c
inner join (
select distinct box, max(process_date) as Proc_dt, trans_amt
from dba.ctopenmo
where trans_code='08' and tc_code='01' and trans_amt >0
group by box, trans_amt) d on d.box=c.box and c.process_date=d.proc_dt
where c.trans_code is null or (c.trans_code='01'
or c.trans_code in = '15'
and c.method_code not in ('3', '4')
and c.tc_code not in ('06', '19')
and c.process_date>='2008-08-14')))
group by c.box, c.trans_code, c.process_date, c.tc_code

bjoerns
Posting Yak Master

154 Posts

Posted - 2008-09-15 : 07:24:05
or c.trans_code in ('15')
Go to Top of Page

ntn104
Posting Yak Master

175 Posts

Posted - 2008-09-15 : 07:36:08
quote:
Originally posted by bjoerns

or c.trans_code in ('15')




Thank you...I did not see that I have both in and '='.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-15 : 07:48:48
Keep track of your paranthesises!
select		c.box,
sum(c.trans_amt) as amt,
c.trans_code,
max(c.dln) as dln,
c.process_date,
c.tc_code
from dba.ctopenmo as c
inner join (
select box,
max(process_date) as Proc_dt,
trans_amt
from dba.ctopenmo
where trans_code = '08'
and tc_code = '01'
and trans_amt > 0
group by box,
trans_amt
) as d on d.box = c.box
and c.process_date = d.proc_dt
where c.trans_code is null
or c.trans_code in ('01', '15')
and c.method_code not in ('3', '4')
and c.tc_code not in ('06', '19')
and c.process_date >= '2008-08-14'
group by c.box,
c.trans_code,
c.process_date,
c.tc_code



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -