views:

37

answers:

3

Consider the fowling structure:

CREATE TABLE [tblEntityLogs]
(
    [EntityLogId] [int] IDENTITY(1,1) NOT NULL,
    [EntityCountCurrent] [float] NOT NULL,
    ...
)

When executing the query underneath I get an empty row returned...

DECLARE @N FLOAT
SET @N = 666

SELECT ISNULL(tblEntityLogs.EntityCountCurrent, @N) AS EntityCountCurrent
FROM tblEntityLogs

And if I do:

SELECT tblEntityLogs.EntityCountCurrent FROM tblEntityLogs

The same thing happens. I don't even get NULL back.

Note: The table is empty.

+4  A: 

This is how it is supposed to work. If you had 5 rows that were all NULL in the table, you would get back five 666.

ck
+4  A: 

If the table is empty then you won't get anything back - it's by design.

Although, I don't why you'd use/test it with IsNull as your table structure doesn't allow Nulls.

Barry
Strange. And yeah; you're right. In the midst of my frustration I threw a random `ISNULL()` in there :) Thanks
roosteronacid
+5  A: 

It's not failing, it's returning no rows because there's no rows to return. You'd get NULL back if there was a row with EntityCountCurrent set to NULL (which can't happen anyway as that column is defined as NOT NULL).

Dave