Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 774
  • Last Modified:

SQL Error: 'Invalid SQL Statement'

Here is my SQL statement :

BREAK ON Company.ID ON Address.ID SELECT Company.ID, Name, Phone1, Phone2, Fax, Email, Description, NAICS, Website, POBox, Street, Addr, City, Province, PostCode, Mailing, FirstName, LastName FROM Company, Address, Contact WHERE Company.ID = Address.ID AND Company.ID = Contact.CompID AND Company.Name LIKE 'C%' ORDER BY Company.ID

It was working until I added the BREAK ON

Here is the error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.

BREAK is a valid SQL statement. Any suggestions?
1 Solution
break is for a while loop:

Sets a condition for the repeated execution of an SQL statement or statement block. The statements are executed repeatedly as long as the specified condition is true. The execution of statements in the WHILE loop can be controlled from inside the loop with the BREAK and CONTINUE keywords.

WHILE Boolean_expression
    { sql_statement | statement_block }
    [ BREAK ]
    { sql_statement | statement_block }
    [ CONTINUE ]


Is an expression that returns TRUE or FALSE. If the Boolean expression contains a SELECT statement, the SELECT statement must be enclosed in parentheses.

{sql_statement | statement_block}

Is any Transact-SQL statement or statement grouping as defined with a statement block. To define a statement block, use the control-of-flow keywords BEGIN and END.


Causes an exit from the innermost WHILE loop. Any statements appearing after the END keyword, marking the end of the loop, are executed.


Causes the WHILE loop to restart, ignoring any statements after the CONTINUE keyword.

If two or more WHILE loops are nested, the inner BREAK exits to the next outermost loop. First, all the statements after the end of the inner loop run, and then the next outermost loop restarts.

A. Use BREAK and CONTINUE with nested IF...ELSE and WHILE
In this example, if the average price is less than $30, the WHILE loop doubles the prices and then selects the maximum price. If the maximum price is less than or equal to $50, the WHILE loop restarts and doubles the prices again. This loop continues doubling the prices until the maximum price is greater than $50, and then exits the WHILE loop and prints a message.

USE pubs
WHILE (SELECT AVG(price) FROM titles) < $30
   UPDATE titles
      SET price = price * 2
   SELECT MAX(price) FROM titles
   IF (SELECT MAX(price) FROM titles) > $50
PRINT 'Too much for the market to bear'

B. Using WHILE within a procedure with cursors
The following WHILE construct is a section of a procedure named count_all_rows. For this example, this WHILE construct tests the return value of @@FETCH_STATUS, a function used with cursors. Because @@FETCH_STATUS may return -2, -1, or 0, all three cases must be tested. If a row is deleted from the cursor results since the time this stored procedure was executed, that row is skipped. A successful fetch (0) causes the SELECT within the BEGIN...END loop to execute.

USE pubs
DECLARE tnames_cursor CURSOR
OPEN tnames_cursor
DECLARE @tablename sysname
--SET @tablename = 'authors'
FETCH NEXT FROM tnames_cursor INTO @tablename
   IF (@@FETCH_STATUS <> -2)
      SELECT @tablename = RTRIM(@tablename)
      EXEC ('SELECT ''' + @tablename + ''' = count(*) FROM '
            + @tablename )
      PRINT ' '
   FETCH NEXT FROM tnames_cursor INTO @tablename
CLOSE tnames_cursor
DEALLOCATE tnames_cursor

You are correct to say that BREAK is a valid SQL statement - and TAshby shows you the correct usage of this word. But you are trying to use BREAK ON which is Oracle specific syntax.

To duplicate the output of the BREAK ON syntax in MSSQL, check out BOL for the ROLLUP keyword.

In Oracle, BREAK ON is not a valid SQL DML command. It a SQL PLUS command. Using for formatting the Select output records.

100% for sure you can not use it with ODBC.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

alzoid69Author Commented:
I can't find any documantation on BOL or ROLLUP.  Can u give me a link?
BOL(Books On-Line) is/should be installed with the MSSQL. If you don't have access to BOL on your desktop then you can get the help here - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/acdata/ac_8_qd_08_7e40.asp

good luck.
Tom KnowltonWeb developerCommented:
No comment has been added lately (214 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to brettc http:#8041648

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --


EE Cleanup Volunteer

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now