Ver Mensaje Individual
  #5 (permalink)  
Antiguo 13/12/2012, 13:05
jnavarrete2311
 
Fecha de Ingreso: noviembre-2012
Mensajes: 30
Antigüedad: 12 años
Puntos: 0
Respuesta: Asignar valor a variable en un SP

Este es el codigo, se que tengo variables de sesion que no deberian de estar en el SP pero estoy tratando de ver como asignar los valors

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 DEFINER=`root`@`localhost` PROCEDURE `InsertOrder`(
  8. IN Nombre VARCHAR(100),
  9. IN Apellido VARCHAR(100),
  10. IN TotalPaidNoTax float,
  11. IN TotalConTax float,
  12. IN ShippingNoTax float,
  13. IN ReferenceCode VARCHAR(100),
  14. IN CurrentState INT,
  15. IN Payment VARCHAR(100),
  16. IN Module VARCHAR(100),
  17. IN Tax float
  18. )
  19.  
  20. /*DECLARE customer_id INT;
  21. SET customer_id = 0;
  22. SELECT id_customer
  23. FROM `ps_customer`
  24. WHERE firstname = Nombre AND lastname= Apellido
  25. INTO customer_id;
  26. SELECT customer_id;*/
  27. /*
  28. SET @var = 0;
  29. SELECT @var := id_customer
  30. FROM `ps_customer`
  31. WHERE firstname = 'Julio' AND lastname= 'Muro';
  32. SELECT @var;*/
  33.  
  34. SET @var = 0;
  35. SELECT @var := id_customer
  36. FROM `ps_customer`
  37. WHERE firstname = Nombre AND lastname= Apellido;
  38. SELECT CAST(@var AS UNSIGNED) idcustomer;
  39.  
  40.     set @id_cart = (select MAX(id_cart) from `ps_cart`);
  41.     set @id_address = (select id_address from `ps_address` where firstname = Nombre and lastname= Apellido);
  42.     -- Declare customer_id INT;
  43.     -- set customer_id = (select id_customer  from `ps_customer` where firstname = Nombre and lastname= Apellido);
  44.     -- Select customer_id
  45.     set @id_guest = (select id_guest from `ps_guest` where id_customer = @customer_id);
  46.  
  47.             insert into  `ps_cart`(id_shop_group,id_shop,id_carrier,delivery_option,id_lang,
  48.                                    id_address_delivery,id_address_invoice,id_currency,id_customer,
  49.                                    id_guest,secure_key,recyclable,gift,gift_message,allow_seperated_package,
  50.                                    date_add,date_upd
  51.                                    )
  52.             select
  53.                   id_shop_group,id_shop,id_carrier,delivery_option,id_lang,id_address_delivery,
  54.                   id_address_invoice,id_currency,id_customer,id_guest,secure_key,recyclable,gift,
  55.                   gift_message,allow_seperated_package,date_add = CURRENT_TIMESTAMP(),
  56.                   date_upd = CURRENT_TIMESTAMP()
  57.             from
  58.                 ps_cart where id_cart = @id_cart;
  59.                        
  60.             set @id_cart = (select MAX(id_cart) from ps_cart);
  61.  
  62.             update `ps_cart` set id_guest=@id_guest, id_address_delivery = @id_address,
  63.                                  id_address_invoice = @id_address, id_customer = @customer_id,
  64.                                  date_add=CURRENT_TIMESTAMP(),date_upd=CURRENT_TIMESTAMP()
  65.             where id_cart=@id_cart;
  66.  
  67.             set @id_cart = (select MAX(id_cart) from ps_cart);
  68.             set @id_order_max = (select MAX(id_order) from `ps_orders`);
  69.             set @invoice_number = (select invoice_number from `ps_orders` where id_order = @id_order_max);
  70.             set @TotalMenosShippingIncl = (TotalPaidNoTax - 2.32);
  71.             set @TotalProductMenosShipping = (TotalConTax  - 2.32);
  72.             set @shippingTax = ShippingNoTax + ((ShippingNoTax * Tax)/100);
  73.            
  74.             insert into `ps_orders`(reference,id_carrier,id_lang,id_customer,id_cart,id_currency,
  75.                                     id_address_delivery,id_address_invoice,current_state,secure_key,
  76.                                     payment,conversion_rate,module,gift_message,shipping_number,
  77.                                     total_paid,total_paid_tax_incl,total_paid_tax_excl,total_paid_real,
  78.                                     total_products,total_products_wt,total_shipping,total_shipping_tax_incl,
  79.                                     total_shipping_tax_excl,carrier_tax_rate,date_add,date_upd
  80.                                     )
  81.                               values(
  82.                                     ReferenceCode,2,4,@customer_id,@id_cart,1,@id_address,@id_address,
  83.                                     CurrentState,'91b5b10c93a6f626f8e6154b32279510',Payment,
  84.                                     1.000000,Module,'','',TotalConTax,TotalConTax,TotalPaidNoTax,
  85.                                     0.00,@TotalMenosShippingIncl,@TotalProductMenosShipping,@shippingTax,
  86.                                     @shippingTax,ShippingNoTax,Tax,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()
  87.                                     );