Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2011

    Unanswered: How does sybase SQL queries differs from MS SQL queries


    I just joined this company and I'm new to Sybase, so I'm looking through their work to see what's happening, I cam across this query which I need help of.

    count(DISTINCT h.hosp_id) AS cases,
    sum(h.totalbenefit) AS total_benefit,
    CONVERT(DECIMAL(10,2),(total_benefit/cases)) AS average_cost_per_admission
    dss."hosp_cases" h

    --> From my understanding of MS T-SQL, the query would start to execute from the "FROM" clause, SELECT would be second last then ORDER BY being the last one to execute. Now from the above query I could help to notice that they have "ONVERT(DECIMAL(10,2),(total_benefit/cases)) AS average_cost_per_admission" as one of the field they are selecting, "total_benefit" and "cases" as aliases.

    --> My question is, is it possible to do Selection like that, and how does Sybase execute, and links if any to study further on Sybase.

  2. #2
    Join Date
    May 2005
    South Africa
    Provided Answers: 1
    SELECT count(DISTINCT h.hosp_id) AS cases,
    and then referencing the alias (total_benefit/cases))
    should produce an error unless the underlying table(s) in the from clause happen to have column names with the same name as the alias in which case your calculation might not produce the answer that you thing it should.

    Maybe this example will help to explain
    SELECT * FROM master..spt_values WHERE type='P' AND number=4
    SELECT high AS number, number+100 AS x FROM master..spt_values v WHERE type='P' AND number=4

    Yes, order by is evaluated last therefore you can reference an alias in your order by but not in the where or select
    i.e. this is valid
    SELECT number AS seq FROM master..spt_values WHERE type='P' ORDER BY seq

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts