Ricky
Ricky

Reputation: 498

How can I implement IsNull and Isempty together in sql server query

here I wanted to check if coming value is empty string or null then use value from Db column.Like I did for is null case. How can i check for empty string in this line of code.Please suggest

II.[NAME] = isNull(IIMODEL.[Name], II.[NAME]), 

Upvotes: 1

Views: 57

Answers (3)

pkr
pkr

Reputation: 1761

case when isnull([column], '') <> '' then [column] else [other] end

Upvotes: 1

Gordon Linoff
Gordon Linoff

Reputation: 1269853

Why not just use explicit comparisons?

(II.[NAME] = IIMODEL.[Name] OR IIMODEL.[Name] IS NULL OR IIMODEL.[Name] = '')

I think the logic is much simpler to follow.

Upvotes: 1

Alexander Petrov
Alexander Petrov

Reputation: 14231

II.[NAME] = ISNULL(NULLIF(TRIM(IIMODEL.[NAME]), ''), II.[NAME])

Upvotes: 2

Related Questions