Respuesta: Asignar valor a variable dentro de if Pues no consigo hacerlo en workbench ni en phpmyadmin, workbench solo me dice que tengo errores de sintaxis pero no me dice donde y phpmyadmin me marca un error en un insert pero no tengo idea de por que este es el query ya con delimiter en phpmyadmin:
Código MySQL:
Ver originalDelimiter // ) (id_default_group ,id_risk ,firstname ,lastname ,email , passwd ,birthday , newsletter_date_add ,max_payment_days ,secure_key ,ac tive ,date_add,date_upd ) 3, 0, Firstname, Lastname, Email, '12345',Birthday,'0000-00-00 00:00:00',0, ); INSERT INTO `ps_customer_group` (id_customer , id_group ) INSERT INTO `ps_guest`(id_operating_system , id_web_browser , id_customer , screen_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 , firstname , address1 , postcode , city , phone , vat_number , dni , DATE_ADD, date_upd , active , deleted ) VALUES(145, 67, Customer_ID , 0, 0, 0, 'Business', Company , Lastname , Firstname , Address1 , Postcode , City , Phone , '','' , CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 1, 0); //
-----------------------------------------------------------------------------------------------------------
y este es el error que marca:
Código MySQL:
Ver originalError Parece haber un error en su consulta de SQL. La salida generada por el servidor de MySQL, de existir, aparece abajo, en cuyo caso puede ayudar a diagnosticar el problema. ERROR: Signo de puntuación desconocido @ 1947 STR: // ) (id_default_group ,id_risk ,firstname ,lastname ,email , passwd ,birthday , newsletter_date_add ,max_payment_days ,secure_key ,ac tive ,date_add,date_upd ) 3, 0, Firstname, Lastname, Email, '12345',Birthday,'0000-00-00 00:00:00',0, ); INSERT INTO `ps_customer_group` (id_customer , id_group ) INSERT INTO `ps_guest`(id_operating_system , id_web_browser , id_customer , screen_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 , firstname , address1 , postcode , city , phone , vat_number , dni , DATE_ADD, date_upd , active , deleted ) VALUES(145, 67, Customer_ID , 0, 0, 0, 'Business', Company , Lastname , Firstname , Address1 , Postcode , City , Phone , '','' , CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 1, 0); // consulta SQL: Documentación 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 DECLARE regs INT; DECLARE ExistsUser INT; DECLARE Customer_ID INT; SET regs = 0; SELECT COUNT(*) INTO regs FROM `ps_customer` WHERE id_customer = 3; IF regs > 0 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 ,'0000-00-00 00:00:00',0, '2293b4751c4ff4517bb997eb9c141a76',1,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP() ); SET Customer_ID = LAST_INSERT_ID(); IF Customer_ID > 0 THEN 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 , screen_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 , firstname , address1 , postcode , city , phone , vat_number , dni , DATE_ADD, date_upd , active , deleted ) VALUES(145, 67, Customer_ID , 0, 0, 0, 'Business', Company , Lastname , Firstname , Address1 , Postcode , City , Phone , '','' , CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 1, 0); END IF; END IF; END // MySQL ha dicho: Documentación #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 'tive,date_add,date_upd) 3, 0, Firstname, Lastna' at line 28
|