Pregunta

atributos Im creación de producto adaptable en una tienda web -. Cada atributo puede tener diferentes tipos de datos, cada tipo de datos se almacena en una columna separada usando correspondiente tipo de datos mysql

Tengo una consulta como:

SELECT
products.id AS id,
products.sku AS sku,
products.name AS name,
products.url_key AS url_key,
attributes.name AS attribute, 

CASE
    WHEN `attribute_types`.`type` = 'text' 
        THEN product_attribute_values.value_text
    WHEN `attribute_types`.`type` = 'float' 
        THEN product_attribute_values.value_float
    WHEN `attribute_types`.`type` = 'price' 
        THEN product_attribute_values.value_float
    WHEN `attribute_types`.`type` = 'integer' 
        THEN product_attribute_values.value_integer
    WHEN `attribute_types`.`type` = 'multiple' 
        THEN product_attribute_values.value_text
    WHEN `attribute_types`.`type` = 'dropdown' 
        THEN product_attribute_values.value_text
    WHEN `attribute_types`.`type` = 'date' 
        THEN product_attribute_values.value_date
    WHEN `attribute_types`.`type` = 'textarea' 
        THEN product_attribute_values.value_textarea
END as value

from (...)

Ahora, el problema es que cuando attribute_types.type es igual a? Algún tipo? yo quiero que devuelve un valor como se encuentra almacenada en la tabla product_attribute_values. Actualmente recibo BLOb cada vez.

¿Debo usar el tipo de fundición a presión o hay algo detrás de la magia de escena que no saben acerca de, o tal vez hay alguna alternativa mejor?

EDIT:

Todo parece estar bien (precio de control de mensajes instantáneos que es float) hasta que puedo añadir una condición para el texto (área de texto).

No hay solución correcta

Otros consejos

Parece que está utilizando un navegador consulta. Trate de ejecutar este comando a través de 'masilla'.

Además, para obtener la salida correcta, incluso en el navegador consulta, incluirá función CAST en su declaración de caso como éste.

CAST(
CASE
WHEN `attribute_types`.`type` = 'text' 
    THEN product_attribute_values.value_text
WHEN `attribute_types`.`type` = 'float' 
    THEN product_attribute_values.value_float
WHEN `attribute_types`.`type` = 'price' 
    THEN product_attribute_values.value_float
WHEN `attribute_types`.`type` = 'integer' 
    THEN product_attribute_values.value_integer
WHEN `attribute_types`.`type` = 'multiple' 
    THEN product_attribute_values.value_text
WHEN `attribute_types`.`type` = 'dropdown' 
    THEN product_attribute_values.value_text
WHEN `attribute_types`.`type` = 'date' 
    THEN product_attribute_values.value_date
WHEN `attribute_types`.`type` = 'textarea' 
    THEN product_attribute_values.value_textarea
END 
AS CHAR) as value
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top