1

I am trying to put a limit on my Sybase SELECT statement query, but I keep getting syntax errors. I've tried using both limit and SELECT * TOP 10, but neither seems to work. This is my SELECT statement code:

      SELECT top 10 * 
      // column params
            FROM claims c
    LEFT OUTER JOIN claims_transaction as ct
        ON ct.claim_id = c.id
    LEFT OUTER JOIN claims_batch_listings cb
        ON cb.batch_listing = c.batchl
    LEFT OUTER JOIN notes_details d
        ON d.id_number = c.notes_detail_id
    LEFT OUTER JOIN individual_ins_xref px
        ON px.pt_id = c.ind_id
        AND px.ins_id = c.ins_id
    LEFT OUTER JOIN individuals ind
        ON ind.id_number = c.ind_id
    LEFT OUTER JOIN sections sec
        ON ind.sec_id = sec.id_number 
    LEFT OUTER JOIN contract_items cont
        ON c.contract_id = cont.contract_id   
            WHERE ( d.date_of_visit >= px.coverage_start AND d.date_of_visit <= px.coverage_end )
                AND visit_type <> 'No Visit'
            ORDER BY c.datetimecreated;
Mureinik
  • 297,002
  • 52
  • 306
  • 350
Muirik
  • 6,049
  • 7
  • 58
  • 116
  • Possible duplicate of [How do I limit the amount of results returned in Sybase?](https://stackoverflow.com/questions/1587135/how-do-i-limit-the-amount-of-results-returned-in-sybase) – melpomene Jun 22 '18 at 13:09
  • 1
    The second answer in that question suggests a solution which doesn't work for my query. In my case, as the answer below indicates, I needed to remove the "*" for the query to run correctly. – Muirik Jun 22 '18 at 13:21
  • `select * from people` works fine. `select field1, field2, field3 from people` also works. What doesn't work is `select * field1, field2, ...`, but that's unrelated to `top 10`. – melpomene Jun 22 '18 at 13:44

1 Answers1

2

The * is wrong. Just lose it and you should be OK:

SELECT top 10 -- * removed here
c.claim_problem as problem,
-- etc.
Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • . . Are you saying that Sybase doesn't support `select *`? – Gordon Linoff Jun 22 '18 at 13:49
  • @GordonLinoff no. Muirik's last edit made the question a bit hard to follow. The original SQL text had `select top 10 * someColumn`, without the missing comma between them. Having `*` and then a list of columns was the mistake here. – Mureinik Jun 22 '18 at 13:51
  • So @Mureinik, what I hear you saying is that "SELECT top 10 *, c.claim_problem..." would have also worked? All I needed was a comma after the asterisk? – Muirik Jun 22 '18 at 15:09
  • 1
    @Muirik yes, should work - although I'd qualify it (`c.*`), just to make the query clearer – Mureinik Jun 22 '18 at 15:12