How to remove empty rows from a SQL result set
I have a request like this:
SELECT DISTINCT
[F_Exhibitor_Name]
FROM
[V_ExhibitorLocation]
WHERE
F_ExhibitionCode ='10996'
AND
[F_Exhibitor_Name] IS NOT NULL
ORDER BY
F_Exhibitor_Name
My first line is blank, which is causing an error in the code. My current result set looks like this:
+3
jase mhi
source
to share
2 answers
In SQL Server null
and empty string ( ''
) do not match. If you want to exclude both, you must explicitly check both:
SELECT DISTINCT [F_Exhibitor_Name]
FROM [V_ExhibitorLocation]
WHERE [F_ExhibitionCode] = '10996' AND
[F_Exhibitor_Name] IS NOT NULL AND
[F_Exhibitor_Name] <> ''
ORDER BY [F_Exhibitor_Name]
+4
Mureinik
source
to share
I can suggest a trick for mixing IS NOT NULL
ANDs <> ''
like this:
SELECT DISTINCT
F_Exhibitor_Name
FROM
V_ExhibitorLocation
WHERE
F_ExhibitionCode = '10996'
AND
F_Exhibitor_Name > '' --or ISNULL(F_Exhibitor_Name, '') <> ''
ORDER BY
F_Exhibitor_Name
+1
shA.t
source
to share