我试过这个:
declare @date as datetime
SET @date = '1/1/1901 12:00:00 AM'
SELECT @date, CONVERT(numeric(9,3), @date) as DateValue
if (isnull(@date,0) = 0) SELECT 'date is zero' ELSE SELECT 'date not equal to zero (THIS PRINTS)'
if (isnull(@date,0) = 365) SELECT 'date is 365 (THIS PRINTS)' ELSE SELECT 'date not equal to zero'
if (@date = 365) SELECT 'date is 365 (THIS PRINTS)' ELSE SELECT 'date not 365'
SET @date = '1/1/1900 12:00:00 AM'
SELECT @date, CONVERT(numeric(9,3), @date) as DateValue
if (isnull(@date,0) = 0) SELECT 'date is equal to Zero (THIS PRINTS)' ELSE SELECT 'date not null'
if (@date = 0) SELECT 'date is equal to Zero (THIS PRINTS)' ELSE SELECT 'date not null'
ISNULL 和 COALESCE都没有错。问题是您正在与零进行比较,并且您自欺欺人地认为 ISNULL 启动了。试试我的代码,看看 ISNULL 返回正确的值。