I have a couple of views which use the SELECT CASE syntax.However when I create a back up scripts and try restoring I get syntax errors.Keep in mind however the view was sucessfully created in the first place.
On of my several “SELECT CASE” syntax view is right here
DROP VIEW IF EXISTS `v_stockmovement` ;
CREATE VIEW `v_stockmovement`
AS
SELECT stock_mov.id AS ID,
stock_category.stock_category_code AS categorycode,
stock_mov_type,
(SELECT CASE stock_mov_type
WHEN 1 THEN 'Stock Issue'
WHEN 2 THEN 'Stock Reorder'
WHEN 3 THEN 'Stock Adjustment'
ELSE '' END) AS stock_mov_typedesc,
(SELECT stock_mov_unitcost * stock_mov_quantity) AS cost,
stock_mov_comments
FROM stock_mov
INNER JOIN stock ON stock.stock_code = stock_mov.stock_mov_linkstockcode
INNER JOIN stock_category ON stock_category.stock_category_code = stock.stock_linkcategory
;
What could I be missing?
try this: (I’ve removed the brackets and the SELECT around the CASE statement)