sql:判断是否存在相同记录,如果存在则改写,不存在则添加

2025-04-06 12:43:53
推荐回答(2个)
回答1:

可以先用
select count(date) into 变量名 from 表名 where date ='2009-4-13'
取date为'2009-4-13'的记录行数,如果为0则用insert语句,如果大于0,则用update语句

只用一条sql语句是出不来的

回答2:

call openconn
sql="select * from 二维表 where date='2009-4-13'"
rs.open,sql,cn.3,3
if rs.recordcount>0
then goto update
if rs.eof then goto addnew
update:
rs!date=2009-4-13
rs!amount=50
rs.update
call closeconn

addnew:

rs.addnew
rs!date=2009-4-13
rs!amount=50
rs.update
call closeconn

VB 可行~~~