开发者

Simple SELECT query fails

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 tb开发者_如何学ClEntityLogs

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

Note: The table is empty.


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).


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜