Alternative to Top 1 in Sybase DB

34 Views Asked by At

I am using Sybase as our db and I have a query where I need to ensure that I only return one record. I have the following query that is returning more than one record and in Sybase you can't use MAX or TOP 1. What are some alternative ways to ensure that only 1 record is returned using the following query. I am also needing to do an "order by rate.effective_date desc" at the end of the query because I need to ensure the most recent date is returned also:

 select @sign_off_amount = -- dps minutes * dpy rate
               --dps duration, dps is in minutes
               convert(money,
               ( select oper_sign_off*1.0/60 from dps_parms where (@effective_dt between effective_dt and expires))
               *
               -- dpy rate/hr
               ( select rate.rate_amount
                   from drv_pay..work_type_sub_category wtsc
                       ,drv_pay..rate rate
                  where wtsc.work_type_sub_desc = 'SIGN OFF TIME'
                    and (wtsc.effective_date <= @effective_dt and wtsc.expire_date >= @effective_dt or wtsc.expire_date = NULL)
                    and wtsc.work_type_seq_nbr = rate.work_type_seq_nbr  and rate.full_part = 'F'
                    and (rate.effective_date <= @effective_dt and (rate.expire_date >= @effective_dt or rate.expire_date = NULL))))

I have tried to use SET ROWCOUNT 1 and SET ROWCOUNT 0 but cannot figure out where to put the syntax for that either.

0

There are 0 best solutions below