Is it possible to insert a record if there is no return from a query

Not sure if this is possible but within my query the snipped bellow returns a result to a previous one, however not every result has a previous one and what I'd like to do is insert a particular date/statement if one isn't found as I need the number of returned rows to be the same as the number of incidents.  

If <Code> Returns No result Instead insert X

INSERT INTO tbIncdientPrev
SELECT top 1 atdtInciedentDateTime, atvCustId, atvcCustFullName, IncidentLevel, atvcLocationName
FROM tbDnTestDateTime
WHERE atvcPatientId = @CustID
AND atdtTestDateTime < @PrevDate
ORDER by atdtTestDateTime DESC

Open in new window

LitationAsked:
Who is Participating?
 
Ess KayEntrapenuerCommented:
yes, its possible.
in pseudocode

if methodnamehere() = (nothing / null) then doinsertstuff()
0
 
LitationAuthor Commented:
I've requested that this question be deleted for the following reason:

needed to change original code couldnt edit
0
 
Ess KayEntrapenuerCommented:
guess that doesnt answer you question.?
0
 
LitationAuthor Commented:
Actually it did, I needed to do some messing around with it but after spending a day away from it going back to it I managed to get it to work, cheers.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.