Ver Mensaje Individual
  #18 (permalink)  
Antiguo 07/12/2012, 12:45
jnavarrete2311
 
Fecha de Ingreso: noviembre-2012
Mensajes: 30
Antigüedad: 11 años, 5 meses
Puntos: 0
Respuesta: Asignar valor a variable dentro de if

Ya logre crearlo ya solo tenia errores de sintaxis en campos que tenian espacio asi quedo la solucion en workbench:
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$

Código MySQL:
Ver original
  1. -- --------------------------------------------------------------------------------
  2. -- Routine DDL
  3. -- Note: comments before and after the routine body will not be stored by the server
  4. -- --------------------------------------------------------------------------------
  5. DELIMITER $$
  6.  
  7. CREATE PROCEDURE `sp_InsertCustomer` (
  8.     IN Firstname VARCHAR(100),
  9.     IN Lastname VARCHAR(100),
  10.     IN Email VARCHAR(100),
  11.     IN Birthday DATETIME,
  12.    
  13.     IN Company VARCHAR(100),
  14.     IN Address1 VARCHAR(100),
  15.     IN Postcode INT,
  16.     IN City VARCHAR(100),
  17.     IN Phone INT
  18. )
  19.  
  20.     DECLARE regs INT;
  21.     DECLARE ExistsUser   INT;
  22.     DECLARE Customer_ID INT;
  23.     SET regs = 0;
  24.     SELECT COUNT(*) INTO regs
  25.     FROM `ps_customer`
  26.     WHERE id_customer = 3;
  27.  
  28.     IF regs > 0 THEN
  29.         SET ExistsUser = 1;
  30.     END IF;
  31.  
  32.     IF ExistsUser = 1 THEN
  33.         INSERT INTO  `ps_customer`
  34.             (id_default_group,id_risk,firstname,lastname,email, passwd,birthday, newsletter_date_add,max_payment_days,secure_key,active,date_add,date_upd)
  35.         VALUES(
  36.                3, 0, Firstname, Lastname, Email, '12345',Birthday,'0000-00-00 00:00:00',0,
  37.                '2293b4751c4ff4517bb997eb9c141a76',1,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()
  38.               );
  39.  
  40.         SET Customer_ID = LAST_INSERT_ID();
  41.         IF Customer_ID > 0 THEN
  42.             INSERT INTO  `ps_customer_group` (id_customer, id_group)
  43.                 VALUES(Customer_ID, 3);
  44.             INSERT INTO  `ps_guest`(id_operating_system, id_web_browser, id_customer, screen_resolution_x, screen_resolution_y,
  45.             screen_color, sun_java, adobe_flash, adobe_director, apple_quicktime, real_player, windows_media, accept_language)
  46.                 VALUES(3, 10, Customer_ID, 0, 0, 0, 0, 0, 0, 0, 0, 0,'');
  47.             INSERT INTO  `ps_address`(id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1,
  48.              postcode, city, phone, vat_number, dni, DATE_ADD, date_upd, active, deleted)
  49.                 VALUES(145, 67, Customer_ID, 0, 0, 0, 'Business', Company, Lastname, Firstname, Address1, Postcode, City, Phone, '','' , CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 1, 0);
  50.         END IF;
  51.     END IF;
  52.  

AUNQUE LA VERDAD ME HA DEJADO UN MAL SABOR MYSQL YO NO RECOMIENDO QUE LO USEN ESTA MUY LIMITADO EN MUCHAS COSAS ES MUCHO MEJOR SQLSERVER Y NI HABLAR CON PHP QUE CONTINUA SIENDO TAN OBSOLETO Y NO PROPORCIONA MUCHA AYUDA PARA DESARROLLAR A LOS PROGRAMADORES, ESTAS DOS TECNOLOGIAS DE VERIAN DE MORIR YA.
GRACIAS POR LA AYUDA gnzsoloyo