Respuesta: Asignar valor a variable dentro de if Mira esto es lo que estoy intentando hacer:
crear un sp que me inserte usuarios en la tabla de ps_customer y sus datos como direcciones telefonos en otras tres tablas, pero antes de eso tengo que validar que el usuario que voy a insertar no exista ya en la tabla, como lo puedes ver aqui:
CREATE PROCEDURE sp_InsertCustomer (
IN Firstname VARCHAR(100), IN Lastname VARCHAR(100), IN Email VARCHAR(100), IN Birthday DateTime,
IN Company varchar(100), IN Address1 varchar(100), IN Postcode INT, IN City varchar(100), IN Phone INT
)
BEGIN
IF (SELECT * FROM `ps_customer` WHERE id_customer = 3) IS NOT NULL THEN
SET @ExistsUser = 1;
END IF;
IF @ExistsUser = 1 THEN
insert into `ps_customer`
(
id_default_group,id_risk,firstname,lastname,email, passwd,birthday,
newsletter_date_add,max_payment_days,secure_key,ac tive,date_add,date_upd
)
values (
3,0,Firstname,Lastname,Email,'12345',Birthday,'000 0-00-00 00:00:00',0,'2293b4751c4ff4517bb997eb9c141a76',1,C URRENT_TIMESTAMP(),
CURRENT_TIMESTAMP()
);
set @Customer_ID = (select MAX(id_customer) from `ps_customer`);
insert into `ps_customer_group` (id_customer,id_group)values(@Customer_ID,3);
insert into `ps_guest`(
id_operating_system,id_web_browser,id_customer,scr een_resolution_x,screen_resolution_y,
screen_color,sun_java,adobe_flash, adobe_director,apple_quicktime,real_player,windows _media,
accept_language
)
values(
3,10,@Customer_ID,0,0,0,0,0,0,0,0,0,''
);
insert into `ps_address`(
id_country,id_state,id_customer,id_manufacturer,id _supplier,id_warehouse,alias,company,lastname,firs tname,address1,
postcode,city,phone,vat_number,dni,date_add,date_u pd,active,deleted
)
values
(
145,67,@Customer_ID,0,0,0,'Business',Company,Lastn ame,Firstname,Address1,Postcode,City,Phone,
'','',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),1,0
);
END IF;
END
------------------------------------------------------------------------------------------
ESE ES EL SP CON EL CODIGO QUE ME PASASTE
Y ESTE ES EL ERROR QUE ME MARCA:
------------------------------------------------------------------------------------------
Error
consulta SQL:
CREATE PROCEDURE sp_InsertCustomer( IN Firstname VARCHAR( 100 ) , IN Lastname VARCHAR( 100 ) , IN Email VARCHAR( 100 ) , IN Birthday DATETIME, IN Company VARCHAR( 100 ) , IN Address1 VARCHAR( 100 ) , IN Postcode INT, IN City VARCHAR( 100 ) , IN Phone INT ) BEGIN IF( SELECT *
FROM `ps_customer`
WHERE id_customer =3 ) IS NOT NULL
THEN
SET @ExistsUser =1;
MySQL ha dicho:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 7
-------------------------------------------------------------------------------------------------------------- |