Solved

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

Posted on 2013-05-13
5
180 Views
Last Modified: 2013-05-15
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

0
Comment
Question by:Litation
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:Ess Kay
ID: 39161959
yes, its possible.
in pseudocode

if methodnamehere() = (nothing / null) then doinsertstuff()
0
 
LVL 15

Accepted Solution

by:
Ess Kay earned 500 total points
ID: 39161967
0
 

Author Comment

by:Litation
ID: 39168508
I've requested that this question be deleted for the following reason:

needed to change original code couldnt edit
0
 
LVL 15

Expert Comment

by:Ess Kay
ID: 39162423
guess that doesnt answer you question.?
0
 

Author Comment

by:Litation
ID: 39168511
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

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question