Can I check only null records in SQL?

I am trying to help an employee with a specific problem, and it is limited only to MS SQL QUERY code. The object is to insert a dummy record (in the surrounding union) if no records are returned from the query.

It is difficult for me to move from PL / SQL to MS SQL, and I seek help (I am not particularly attractive, but I appeal to the StackOverflow audience).

Basically, we need one test value from the target Select statement ...

In theory, this would do this:

(other records from unions)
Union
   Select "These" as fld1, "are" as fld2, "Dummy" as fld3, "Fields" as fld4 
   where NOT (Matching Logic)
Union
   Select fld1, fld2, fld3, fld4  // Regular records exist
   From tested_table
   Where (Matching Logic)

Setting a separate dummy recording without any conditions.

Is there a way to get one testable result from Select?

Unable to do this in code (not allowed), but can feed SQL

Is anyone Is anyone Bbeller?

+3
source share
1

unions with, , null, :

; with BigUnion as
         (
         select  *
         from    table1
         union all
         select  *
         from    table2
         )
select   *
from     BigUnion
union all
select   null
where    not exists (select * from BigUnion)
+2

Source: https://habr.com/ru/post/1785310/


All Articles