Skip to content
Advertisement

Token unknown in Firebird

This query is throwing an error on firebird, how to resolve that error?

  SELECT EMPNO,SAL 
         FROM EMP E 
         where EMPNO = (SELECT MAX(DEPTNO) FROM DEPT D WHERE E.ENAME NOT like (SELECT TOP 1 ENAME 
                                                                              FROM emp E1 
                                                                              WHERE E1.EMPNO=D.DEPTNO))
         OR 1 = (SELECT MAX(DEPTNO)
                 FROM DEPT D 
                 WHERE E.ENAME like substring('NAME111',1,5))  ORDER BY EMPNO;

Here is the error.

The following error information describes the failure

ODBC Call = SQLPrepareW()

SQL State = HY000

Native error = -104(FFFFFF98)

Error Message = [ODBC Firebird Driver][Firebird]Dynamic SQL Error

SQL error code = -104

Token unknown – line 1, column 111

Advertisement

Answer

(edit to include alternative, more modern syntax from comments)

Instead of SELECT TOP 1 ENAME, use any of the following:

  • SELECT ENAME ... FETCH FIRST ROW ONLY (SQL:2008, Firebird 3+)
  • SELECT ENAME ... ROWS 1 (non-standard, Firebird 2+)
  • SELECT FIRST 1 ENAME ... (non-standard, effectively Firebird 1.5+)

Also, use

substring('NAME111' from 1 for 5)

instead of

substring('NAME111',1,5)

For example, using FIRST 1:

SELECT EMPNO,SAL
  FROM EMP E
  WHERE EMPNO = (SELECT MAX(DEPTNO)
                        FROM DEPT D
                        WHERE E.ENAME NOT LIKE (SELECT FIRST 1 ENAME
                                                  FROM emp E1
                                                  WHERE E1.EMPNO=D.DEPTN O))
        OR 1 = (SELECT MAX(DEPTNO)
                  FROM DEPT D
                  WHERE E.ENAME LIKE substring('NAME111 ' from 1 for 5))
  ORDER BY EMPNO;
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement