Mal*_*loz 2 mysql isnull where
我有这个记录:
SELECT sc.no, scl.quantite, scl.description, scl.poids, scl.prix, sl_ref.refsl, sl_ref.codetva, sl_ref.tauxtva, sl_ref.compte
FROM shop_commande
AS sc, shop_commande_ligne AS scl, selectline_ref AS sl_ref
WHERE sc.id = scl.shop_commande_id
AND sl_ref.refshop = ISNULL(scl.shop_article_id, 0)
AND sc.id NOT IN (SELECT id_command FROM selectline_flag)
Run Code Online (Sandbox Code Playgroud)
有时,在sl_shop_article_id中,有一个NULL值。我想要的是将其替换为0,这样子句:
sl_ref.refshop = scl.shop_article_id
Run Code Online (Sandbox Code Playgroud)
即使scl.shop_article_id为NULL 也可以工作。为此,我尝试使用ISNULL函数,但它使请求出错,并且出现错误:
1582-对本机函数“ ISNULL”的调用中的参数计数不正确
如何使用?
我相信您正在尝试使用该IFNULL()功能。如果您替换ISNULL为IFNULL那个,则可以解决您的查询。
我建议您更进一步,并使用COALESCE()代替IFNULL(),因为它COALESCE()是SQL标准的一部分(IFNULL()不是)。
SELECT sc.no, scl.quantite, scl.description, scl.poids,
scl.prix, sl_ref.refsl, sl_ref.codetva, sl_ref.tauxtva, sl_ref.compte
FROM shop_commande
AS sc, shop_commande_ligne AS scl, selectline_ref AS sl_ref
WHERE sc.id = scl.shop_commande_id
AND sl_ref.refshop = COALESCE(scl.shop_article_id, 0)
AND sc.id NOT IN (SELECT id_command FROM selectline_flag)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14502 次 |
| 最近记录: |