0

I have an SQL Job which takes two values out of a table and merges them together. After the merge, these two values are deleted.

If the table is empty, the Job produces Error-Messages. How can i prevent this?

Kind regards

  • 1
    Table empty (no rows) or not created? In any case you can do this validation easily with SQL. For the first case you can use `IF EXISTS ()` for the second you can check against `sys.tables` (for example) to check if table exists. – EzLo Dec 18 '18 at 07:50
  • 1
    Have a look at this question it seems very similar to yours https://stackoverflow.com/questions/14072140/using-if-else-statement-based-on-count-to-execute-different-insert-statements – Eponyme Web Dec 18 '18 at 07:51
  • @EzLo The table is created but empty. So i will try it with the IF EXISTS(). Tank you – xcrookedxedge Dec 18 '18 at 07:52
  • @Eponyme Web I will have a look at it, thanks! – xcrookedxedge Dec 18 '18 at 07:53

1 Answers1

1

You would add a condition to check for an empty table:

if exists (select 1 from t)
begin
     -- the merge code or procedure call here
end;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786