INSERT INTO TABLE IF NOT NOT EXISTS RECORD in table Is Inserting Multiple multiple multiple record [英] INSERT INTO TABLE IF NOT EXISTS RECORD in table Is Inserting Multiple times single record

查看:59
本文介绍了INSERT INTO TABLE IF NOT NOT EXISTS RECORD in table Is Inserting Multiple multiple multiple record的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



以下是sql语句,如果表中只存在记录,则插入记录..但是我写的语句是多次插入相同的记录...请帮我解决我的问题..




The below is the sql statement that inserts the record if only the record is not exists in table.. but the statement i written is inserting multiple times the same record... please help me to resolve my problem..

INSERT INTO TableName(AccountNo,Customer,ContactNo) select 'AP1234','Saketh','984822338'  FROM TableName WHERE NOT EXISTS(Select * From TableName Where AccountNo='AP1234');

推荐答案

试试这个



希望它能帮到你



INSERT INTO TableName(AccountNo,Customer,ContactNo)选择'AP1234','Saketh ',''984822338'来自TableName WHERE

'AP1234'+'Saketh'+'984822338'NOT In(选择不同的合并(AccountNo,'')+ coalesce(Customer,'')+ coalesce( ContactNo,'')来自TableName);
try this

hope it would help you

INSERT INTO TableName(AccountNo,Customer,ContactNo) select 'AP1234','Saketh','984822338' FROM TableName WHERE
'AP1234'+'Saketh'+'984822338' NOT In (Select distinct coalesce(AccountNo,'')+coalesce(Customer,'')+coalesce(ContactNo,'') From TableName);


我在一些训练后发现自己..

我必须添加DISTINCT来选择命令



现在只插入单次记录,(使用DISTINCT多次npt)



i found myself after some workouts..
I Have To add DISTINCT to select command

now it Inserting The Record Single Time Only,(npt multiple times by using DISTINCT)

INSERT INTO TableName(AccountNo,Customer,ContactNo) select DISTINCT 'AP1234','Saketh','984822338'  FROM TableName WHERE NOT EXISTS(Select DISTINCT AccountNo From TableName Where AccountNo='AP1234');


这篇关于INSERT INTO TABLE IF NOT NOT EXISTS RECORD in table Is Inserting Multiple multiple multiple record的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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