Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

SQL - Hide Prices where decimal fields are 0

  • 22-06-2013 2:15pm
    #1
    Registered Users, Registered Users 2 Posts: 768 ✭✭✭


    Guys....doing a favour for a friend and he needs a MySQL database with products and two different prices.

    Price A has prices on every product while
    Price B only applies to some products as an alternative size.

    How can I hide results of this column where the price is 0.00.

    thanks


Comments

  • Registered Users, Registered Users 2 Posts: 450 ✭✭SalteeDog


    If it was Oracle you could use a 'Decode' function. Perhaps in MySQL it's CASE or IF.


  • Registered Users, Registered Users 2 Posts: 768 ✭✭✭EIREHotspur


    Thanks for that SalteeDog

    Tried a lot of Case examples now with no luck.

    MySQL database is db1 and has
    product_id
    product_name
    product_photo
    price_1
    price_2

    I want to show product_id, product_name and price_1 under product_photo.
    I also want price_2 to appear under each product but only show if the price isn't 0.

    Any examples I see deal with records and not cells or values themselves.


  • Registered Users, Registered Users 2 Posts: 1,034 ✭✭✭dalta5billion


    Thanks for that SalteeDog

    Tried a lot of Case examples now with no luck.

    MySQL database is db1 and has
    product_id
    product_name
    product_photo
    price_1
    price_2

    I want to show product_id, product_name and price_1 under product_photo.
    I also want price_2 to appear under each product but only show if the price isn't 0.

    Any examples I see deal with records and not cells or values themselves.

    How are you displaying the data? Could you filter there? (E.g. PHP or something?)


  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    Does the following work ? I'm not a MySQL guy
    [PHP]

    SELECT
    product_id,
    product_name,
    product_photo,
    price_1,
    CASE
    WHEN price_2 =0 THEN NULL
    ELSE price_2
    END
    FROM
    mytable

    [/PHP]


  • Registered Users, Registered Users 2 Posts: 768 ✭✭✭EIREHotspur


    amen wrote: »
    Does the following work ? I'm not a MySQL guy
    [PHP]

    SELECT
    product_id,
    product_name,
    product_photo,
    price_1,
    CASE
    WHEN price_2 =0 THEN NULL
    ELSE price_2
    END
    FROM
    mytable

    [/PHP]

    Thanks lads...I am going to test out this amen and will tell you if it works.


  • Advertisement
Advertisement