I use Visual Basic 6.0 with SQL Server 2005
Here is my code :
Cn.Execute "INSERT INTO schedule (sch_name, st_id, sch_note)
SELECT '" & txtSchedname.Text & "', st_id, '" & txtNote.Text & "'
FROM scheduletype
WHERE st_name = '" & cboSchedtype.Text & "'"
This is an insert into select statement and works fine. Two inputs directly saved into the [schedule] table and one input coming from [scheduletype] table.
But what if there is no matching records for cboSchedtype.Text?
SELECT st_id
FROM scheduletype
WHERE st_name = '" & cboSchedtype.Text & "'"
Here's I want to do :
I. Make a 'sub-insert' for the value of cboSchedtype.Text into the [scheduletype] table only if it doesn't exist (before the main insert query does its thing)
II. Otherwise continue normally. (My code successfully does this.)