#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

    Unhappy Help me with basic select statements please.


    Hi guys.

    I just don't get why this SELECT statements doesn't work as they work on the MS SQL Server. I know, two different engines. But what am I doing wrong?

    FIRST EXAMPLE:

    SELECT 5

    I would expect to get a result with one row and one column and the value 5, instead of I am getting this error in FlameRobin:

    Preparing query: SELECT 5
    Error: *** IBPP::SQLException ***
    Context: Statement::Prepare( SELECT 5 )
    Message: isc_dsql_prepare failed

    SQL Message : -104
    Invalid token

    Engine Code : 335544569
    Engine Message :
    Dynamic SQL Error
    SQL error code = -104
    Unexpected end of command - line 1, column 8


    SECOND EXAMPLE:

    SELECT *, (1+1) AS test FROM CITIES

    Again, I would expect to have in each row a collumn called test with the value of 2 in it. Instead:

    Error: *** IBPP::SQLException ***
    Context: Statement::Prepare( SELECT *, (1+1) AS test FROM CITIES )
    Message: isc_dsql_prepare failed

    SQL Message : -104
    Invalid token

    Engine Code : 335544569
    Engine Message :
    Dynamic SQL Error
    SQL error code = -104
    Token unknown - line 1, column 9
    ,


    I don't get it. The comma is an unknown token, why?


    THIRD EXAMPLE:

    set term ^ ;

    EXECUTE BLOCK
    AS
    DECLARE VARIABLE var_SecondsOfTime INTEGER;

    BEGIN
    SELECT 1 from RDB$DATABASE into :var_SecondsOfTime ;
    SELECT var_SecondsOfTime ;
    END
    ^

    set term ^ ;

    I would expect to get one row, one collumn with the value hold by the variable var_SecondsOfTime. But again, there is an error:

    Preparing query:

    EXECUTE BLOCK
    AS
    DECLARE VARIABLE var_SecondsOfTime INTEGER;

    BEGIN
    SELECT 1 from RDB$DATABASE into :var_SecondsOfTime ;
    SELECT var_SecondsOfTime ;
    END

    Error: *** IBPP::SQLException ***
    Context: Statement::Prepare(

    EXECUTE BLOCK
    AS
    DECLARE VARIABLE var_SecondsOfTime INTEGER;

    BEGIN
    SELECT 1 from RDB$DATABASE into :var_SecondsOfTime ;
    SELECT var_SecondsOfTime ;
    END
    )
    Message: isc_dsql_prepare failed

    SQL Message : -104
    Invalid token

    Engine Code : 335544569
    Engine Message :
    Dynamic SQL Error
    SQL error code = -104
    Token unknown - line 9, column 28
    ;

    Semicolon an unknown token???


    Thanks for your help.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2007
    Posts
    36
    Rep Power
    8
    For first and third example:
    select statement should always have the clause "from"

    SELECT 1 from RDB$DATABASE into :var_SecondsOfTime ;

    For second example try this:

    SELECT CITIES.*, (1+1) AS test FROM CITIES

    and will work.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0
    Originally Posted by costin_mentor
    For first and third example:
    select statement should always have the clause "from"

    SELECT 1 from RDB$DATABASE into :var_SecondsOfTime ;

    For second example try this:

    SELECT CITIES.*, (1+1) AS test FROM CITIES

    and will work.
    Thank you, all is working fine now.

IMN logo majestic logo threadwatch logo seochat tools logo