Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Empty string instead of NULL

Author  Topic 

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2010-06-15 : 12:02:19
Hi,

I have the following code which works fine but instead of the highlighted field being NULL it is an empty string. How can I make the select statement insert "No Category". Presently, it is inserting an empty string. category_name has been set as nvarchar(50).

Thanks

SELECT DISTINCT 
TOP (100) PERCENT t3.ProjectID, t3.goldPatID, t2.prac_no, t2.prac_eid, t1.goldpracid, t1.vision_patid, t1.yob AS BirthYear, t1.mob AS BirthMonth,
dbo.lkupPatientGender.Sex, ISNULL(t3.category_name, 'No Category') AS PatCategory, { fn NOW() } AS Entrydt, t3.LoadRef
FROM GPRDTech.gprdsql.TblPracDetails AS t2 INNER JOIN
GPRDData.dbo.tblpatdetails AS t1 ON t2.GoldPracID = t1.goldpracid INNER JOIN
dbo.tblImport AS t3 ON t1.goldpatid = t3.goldPatID INNER JOIN
dbo.lkupPatientGender ON t1.gender = dbo.lkupPatientGender.Code
ORDER BY t3.goldPatID

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-06-15 : 12:13:39
I think it is because there isn't a NULL in the column hence the ISNULL() has nothing to do...
Try:
ISNULL(NULLIF(ltrim(rtrim(t3.category_name)),''), 'No Category') AS PatCategory


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-16 : 02:51:31
or

case when t3.category_name='' or t3.category_name is null then 'No Category' else t3.category_name end AS PatCategory

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -