我有一种情况,我想为多个城市的不同产品依次生成invoice_id。我想根据不同的产品和城市获取生成的发票ID。
我的桌子 temp
外观
id |order_id |product|city|invoice_id
1 | 123 | 1 | 1 | FPU1
2 | 124 | 6 | 1 | PPU1
我要为产品1获取下一个 invoice_id
,城市1是FPU2。
对于产品1和城市2是FBN1,对于产品6和城市1是PPU2,依此类推...。
我创建了函数但没有运行。函数有什么问题吗?
CREATE function generate(p_id INT, c_id INT)
returns VARCHAR(50)
BEGIN
-- DECLARE v_new_id VARCHAR(50);
SELECT Concat(( CASE
WHEN t.product = 1 THEN "f"
WHEN t.product = 6 THEN "p" end ),
c.city_name, Cast(RIGHT(t.invoice, Length(t.invoice) - 3) AS UNSIGNED) + 1
) v_new_id
FROM temp AS t
JOIN city c
ON c.city_id = t.city
WHERE t.product = p_id
AND t.city = c_id;
RETURN( v_new_id );
end;
获取语法错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 15
###第15行是AND t.city = c_id;
答案 0 :(得分:0)