Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2002

    Unanswered: case statement limitation

    For version 11.5 and 11.9.2.

    Is this statement true? If not how to correct it?
    You want to use case statement you have to use with a query clause as:
    select pub_id
    when "444" then "It is 444"
    when "455" then "It is 455"
    else "Other id!"
    from titles

    If not you get error as:
    declare @aa int
    select @aa = 4
    case @bb
    when "2" then "It is 2"
    when "4" then "It is 4! you got it"
    other "Get lower number"
    -- Incorrect syntax near the keyword 'case'

  2. #2
    Join Date
    Sep 2002
    Sydney, Australia
    It appears your question is a matter of understanding.
    1 SQL is Structured Query Language, intended for manipulating data in a database (ie. tables and columns). It is not a scripting language (eg./bin/sh, perl) or a programming language (eg. C). The CASE statement is implemented in the context of SQL, ie. it operates in the context of a column value (the examples in the manuals are quite good) in a SELECT, not in the context of a variable as in a programming language. It eases the handling or denormalised or unnormalised tables or raw imported files. A simple example:
        CASE column_2
            WHEN "A" THEN "Fat"
            WHEN "B" THEN "Thin"
            ELSE "Unknown"
    FROM mytable
    (you can make it quite complex and dependent on other columns, etc, refer doco)

    2 There is no 'limitation' in Sybases SQL CASE implementation, the error is not in the implementation, it is in your assumed concept of what CASE does. In fact it is what we asked for, with far more flexibility than (eg.) MS implementation. It is not intended to support the C case function, if you want that, simply use a series of IF statements.
    Last edited by DerekA; 09-23-02 at 23:24.
    Derek Asirvadem
    Senior Sybase DBA/Information Architect derekATsoftwaregemsDOTcomDOTau
    Anything worth doing is worth doing Right The First Time
    Spend your money on standards-compliant development or spend 10 times more fixing it

Posting Permissions

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