SimonSellick
Programmer
Hi,
I am trying to develop a data creation script using variables whose values aren't known until the script runs. In SQL Server the syntax would be something like this:
I know that I can write the scripts to use
...but it's going to look a bit clumsy and be much longer and harder to maintain. Does anyone know if there is a MySQL equivalent to the code above that works outside a procedure? The following fails with a syntax error:
Sorry if this is a bit basic, but I cannot find anything in the 5.1 manual. Should I have bought a book?
Any help / pointers would be appreciated.
I am trying to develop a data creation script using variables whose values aren't known until the script runs. In SQL Server the syntax would be something like this:
Code:
declare @a integer;
select @a = id from ref where code = 'A';
insert into tbl(col, ref) values ('fred', @a);
go
Code:
INSERT ... SELECT
Code:
delimiter /go
declare aa integer;
select aa = id from ref where code = 'AA';
insert into tbl(col, ref) values ('fred', aa);
/go
Any help / pointers would be appreciated.