sql server 2008 return value getting shortened when using ISNULL and NULLIF -
i have select statement check whether phone number in null or empty , if return 'no phone number available'. this
select name, isnull(nullif(phone, ''), 'no phone number available') phone person
but when phone number null or empty not getting full text 'no phone number available'. first 20 characters getting returned. length of phone field 20. think returning text depending on length of phone field.
is there way correct without changing field length?
you correct.
isnull uses datatype , length of first parameter. coalesce takes "highest precedence" one. so:
coalesce(nullif(phone, ''), 'no phone number available') phone
or
isnull(nullif(cast(phone varchar(30)), ''), 'no phone number available') phone
Comments
Post a Comment