Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run SQL query based on the previous output

Tags:

sql

The following query results only "Operation is Success" whilst my aim is to run the "Select" statement listed under IF TRUE condition:

DECLARE @TOTAL int

Select @TOTAL = count(barcode) 
from domain_Media 
where ( (librarySlotNumber > -1) 
  AND (UPPER(volumePoolName) LIKE UPPER('scratch%')) 
  AND (id LIKE '05%' or id LIKE 'DX%') 
  AND (masterServerId = 17785613) )

IF (@TOTAL > 5)
BEGIN
  select * 
  from domain_Media 
  where (masterServerId = 17785613)
END

Where am I going wrong?

like image 279
Prax Avatar asked Oct 27 '25 09:10

Prax


1 Answers

Why not just use a single query?

select * 
from domain_Media 
where masterServerId = 17785613 and
      (select count(barcode) 
       from domain_Media 
       where librarySlotNumber > -1 and
             upper(volumePoolName) like upper('scratch%') and
             (id like '05%' or id like 'DX%') and
             masterServerId = 17785613
      ) > 5;
like image 159
Gordon Linoff Avatar answered Oct 29 '25 23:10

Gordon Linoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!