MySQL INSERT,在为null时进行查找 [英] MySQL INSERT with lookup when null

查看:109
本文介绍了MySQL INSERT,在为null时进行查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当查询表中包含某些内容时,我可以使用以下查询.但是,如果"z.a"不等于任何值,则INSERT失败.为什么会这样?

I have the following query that works when the Lookup table has something in it. However if "z.a" doesn't equal anything the INSERT fails. Why would this be?

 INSERT INTO dataTable(
    a,
    b,
    c,
    d,
    e,
    f,
    g,
    h,
    i,
    j,
    k,
    l,
    m,
    n,
    o,
    p
)SELECT
    '000003',
    COALESCE(z.Registration, 'REG6'),
    'PFTEST',
    '1',
    '1',
    '37000.0',
    '148.0',
    '439.8',
    '1312475688',
    '0',
    '54',
    COALESCE(z.TypeCode, 'A555'),
    '',
    '1173',
    '0',
    'nJ'
FROM
    LookupTable z
WHERE
    z.a = '000003' 

推荐答案

最后,我完全删除了WHERE,并在VALUES直接中执行了选择.效果很好

In the end I removed the WHERE completely and performed selects within the VALUES direct. Works very well

这篇关于MySQL INSERT,在为null时进行查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆