I am using below query to fetch column value by comma separated.
(SELECT STUFF ((SELECT ',' + CAST(Proj_ID AS VARCHAR) FROM PROJECT
left join dbo.PROJ_STA on
Project.PROJ_STA_ID = Project.PROJ_STA_ID
WHERE ENTER_DT < DATEADD(Year, -7, GETDATE()) AND PROJ_LFCYC_STA_CD = 'A' AND
PROJ_STA.PROJ_STA_DS = 'Cancelled' FOR XML PATH('')), 1, 1, '')
AS Enter_Date)
Can anyone guide me to replace null value by empty string here.
Updated:
(SELECT STUFF ((SELECT ',' + coalesce( CAST(Proj_ID AS VARCHAR), '' ) FROM PROJECT
left join dbo.PROJ_STA on
Project.PROJ_STA_ID = Project.PROJ_STA_ID
WHERE ENTER_DT < DATEADD(Year, -7, GETDATE()) AND PROJ_LFCYC_STA_CD = 'A' AND
PROJ_STA.PROJ_STA_DS = 'Cancelled' FOR XML PATH('')), 1, 1, '')
AS Enter_Date)
Try
IsNull
OR
COALESCE
An example from the AdventureWorks database
By using this, if there are no matching Person records, the FirstName will be displayed as an empty string instead of NULL
You can white out null values with the coalesce function
Coalesce takes any number of columns or constants and returns the first one which isn't null.
Your query would be: