G
Guest
HI, hopefully someone has a simple solution to this:
I'm trying to insert a record if it DOESN'T already exist, in one statement. I'm not using explicit transactions so one statement equates to one transaction.
So I want it to be one statement.. in SQL Server, I would do
if not exists (select * from table1 where mycol = 'myval')
insert table1(mycol) values('myval')
but in Access I seem to have had to resort to
insert into table1(mycol)
select 'myval' from table1
where (not exists (select * from table1 where mycol='myval'))
this seems to work, but it seems a little bit 'hacky', as I'm not using the from clause at all... anyone know a better way?
I'm trying to insert a record if it DOESN'T already exist, in one statement. I'm not using explicit transactions so one statement equates to one transaction.
So I want it to be one statement.. in SQL Server, I would do
if not exists (select * from table1 where mycol = 'myval')
insert table1(mycol) values('myval')
but in Access I seem to have had to resort to
insert into table1(mycol)
select 'myval' from table1
where (not exists (select * from table1 where mycol='myval'))
this seems to work, but it seems a little bit 'hacky', as I'm not using the from clause at all... anyone know a better way?