Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force a SQL Server query to return no rows

Tags:

sql

sql-server

I have the following query:

SELECT 
     CASE
          WHEN ([DBO].fn_WorkDays(GETDATE(), DATEADD(d, 1, EOMONTH(GETDATE()))) = 2)
               THEN 1
     END

That should return 1 if the condition is true (obviously), but I want it to return nothing (no rows) if false. Instead, it's returning a null row. How do I force it to return 1 or nothing?

like image 204
Aginor Avatar asked Jan 18 '26 22:01

Aginor


2 Answers

How about

IF [DBO].fn_STRS_WorkDays(GETDATE(), DATEADD(d, 1, EOMONTH(GETDATE()))) = 2
    SELECT 1
like image 155
Alex K. Avatar answered Jan 21 '26 05:01

Alex K.


select * from dbo.table where 1=0

like image 44
user3210023 Avatar answered Jan 21 '26 05:01

user3210023



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!