简体   繁体   中英

Does SQL Server 2014 support functions such as ISNOTNULL()?

dont you know how to change ISNULL() to ISNOTNULL() in MS SQL? Something like IFNULL?

I need to do it in one step.

Set @EMAILhtml = @CSS + @TEXT1 + isnull(@TEXT1,'') +  isnull(@table1,'') + isnull(@text2,'') + isnull(@table2,'')  + @TEXT3

But I need something like

Set @EMAILhtml = @CSS + @TEXT1 + isNOTnull(@TEXT1,'') +  isnull(@table1,'') + isnull(@text2,'') + isnull(@table2,'')  + @TEXT3

Thanks.

I think you've got something wrong:

ISNULL() is used to set a default value in case of NULL

DECLARE @v1 VARCHAR(10)='test';
SELECT ISNULL(@v1,'default') --returns `test`;
SET @v1=NULL;
SELECT ISNULL(@v1,'default') --returns `default`;

Checking for NULL is done with IS NULL . The opposite is IS NOT NULL

DECLARE @v1 VARCHAR(100)=NULL;
SELECT CASE WHEN @v1 IS NULL THEN 'v1 is null' END

The third option in this context is NULLIF() , which returns NULL if a condition is fullfilled

DECLARE @v1 VARCHAR(10)='test';
SELECT NULLIF(@v1,'test'); --returns NULL, because @v1='test'

And last but not least there is COALESCE() . It will return the first non-null value of a list of paramters:

DECLARE @v1 VARCHAR(10)=NULL;
DECLARE @v2 VARCHAR(10)=NULL;
DECLARE @v3 VARCHAR(10)='test';
SELECT COALESCE(@v1,@v2,@v3); --returns 'test'

are you referring to IS NULL and IS NOT NULL ?
as in -

select * from t where x is null
select * from t where x is not null

I don't understand why are you trying to retrieve if is not null this way. The ISNULL() function help to substitute a NULL value to a default one

I suggest to try something like that:

CASE WHEN column IS NOT NULL THEN 'Hey is not null' ELSE 'Sorry, is null!' END

Hope this could help.

 set @TEXT1 = (case when @table1 is null then null else @TEXT1 end)

决赛前

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM