help in Query F1...

  • Thread starter Thread starter krisworld
  • Start date Start date
K

krisworld

dear all
this might be a simple one to many, but I am struck in this Query.

Problem:
I want to insert into a table some records which i need to fetch from
select statement.
Now if the select statement does has a record it its fine.
but if it does not has a record a default valule should be inserted.
some thing like

insert into mytable (field1) select field1, (select count(*) from
table1 where field2="something") from table1 where field1="target"

any idea to help

thanks

krisworld
 
I would use a join of 2 tables like below:


INSERT INTO mytable( field1 )
SELECT IIf(IsNull(.[field1]),"default",.[field1]) FROM table1 AS a
LEFT JOIN table2 AS b ON a.ID = b.ID;

Note table1 is where you know the record exists and table2 may or may not
have the record. If it does not, the record would be null, so you enter the
default.

Please let me know if I can provide more assistance.
 
Back
Top