user153923
user153923

Reputation:

Building and Testing with MySQL Workbench for SSMS People

I am great with Microsoft's SQL Server and SQL Server Management Studio (SSMS).

I'm trying to get things I used to do there to work in MySQL Workbench, but it is giving me very unhelpful errors.

Currently, I am trying to write an INSERT statement. I want to declare my variables and test it with a few values, then turn the end result into a stored procedure.

Right now, I have a syntax error that is not allowing me to continue, and the error message is not helpful either:

syntax error, unexpected DECLARE_SYM

There is no error list at the bottom and no way to copy the text of that error to the clipboard, so it all has to be studied on one screen, then flip to this screen so I can write it down.

Irritating!

The MySQL documentation surely has what I'm looking for, but I can learn much faster by doing than spending weeks reading their online manual.

DELIMITER $$

declare cGroupID char(6) DEFAULT = 'ABC123';
declare subGroupRecords int;
declare nDocTypeID int(11);
declare bDocActive tinyint(1) DEFAULT '1';
declare cDocID varchar(256) DEFAULT NULL;

  insert into dbo_connection.documents
  (group_id, subgroup_id, type_id, active, title, doc_id, priority, ahref, description, last_modified)
  values
  (cGroupID,cSubGroupID,nDocTypeID,bDocActive,cTitle,cDocID,0,ahref1, docDesc,NOW());

select * from dbo_connection.documents where group_id='ABC123';


END

screenshot

So, for right now, I'm looking for why MySQL does not like my declare statement.

For the long term, I'm interested in finding a short article that shows a cookbook approach to doing some of the basic tasks that SQL developers would need (i.e. skips the Hello World program and discussion on data types).

Upvotes: 0

Views: 280

Answers (1)

dpw
dpw

Reputation: 1586

DECLARE is only valid within stored programs. In other words, unlike T-SQL, you can't build up your query and then wrap CREATE PROCEDURE around it to turn the end result into a stored procedure, you have to build it up as a stored procedure from the get-go.

Upvotes: 1

Related Questions