SQL Cannot find if blank field is NULL or '' - TagMerge
4SQL Cannot find if blank field is NULL or ''SQL Cannot find if blank field is NULL or ''

SQL Cannot find if blank field is NULL or ''

Asked 1 years ago
1
4 answers

Can you try to use

WHERE EMail LIKE '%' + CHAR(160) + '%' 

160 is the ascii for "non breaking space".

Source: link

0

Try :

SELECT * FROM xxx
WHERE Email IS NULL OR Email NOT LIKE REPLICATE('[A-Za-z0-9@.-_]', LEN(Email))

Source: link

0

I have a column in a table which might contain null or empty values. How do I check if a column is empty or null in the rows present in a table?
(e.g. null or '' or '  ' or '      ' and ...)
This will select all rows where some_col is NULL or '' (empty string)
SELECT * FROM table WHERE some_col IS NULL OR some_col = '';
As defined by the SQL-92 Standard, when comparing two strings of differing widths, the narrower value is right-padded with spaces to make it is same width as the wider value. Therefore, all string values that consist entirely of spaces (including zero spaces) will be deemed to be equal e.g.
'' = ' ' IS TRUE
'' = '  ' IS TRUE
' ' = '  ' IS TRUE
'  ' = '      ' IS TRUE
etc
Therefore, this should work regardless of how many spaces make up the some_col value:
SELECT * 
  FROM T
 WHERE some_col IS NULL 
       OR some_col = ' ';
or more succinctly:
SELECT * 
  FROM T
 WHERE NULLIF(some_col, ' ') IS NULL;

Source: link

0

I need something like
SELECT * FROM table AS t WHERE ANY(t.* IS NULL)
I don't want to have to do
SELECT * FROM table AS t WHERE t.c1 = NULL OR t.c2 = NULL OR t.c3 = NULL
An extension to @db2's answer with less (read:zero) hand-wrangling:
DECLARE @tb nvarchar(512) = N'dbo.[table]';

DECLARE @sql nvarchar(max) = N'SELECT * FROM ' + @tb
    + N' WHERE 1 = 0';

SELECT @sql += N' OR ' + QUOTENAME(name) + N' IS NULL'
    FROM sys.columns 
    WHERE [object_id] = OBJECT_ID(@tb)
    AND is_nullable = 1;

EXEC sys.sp_executesql @sql;
You should list out all the columns as per JNK's comment.
WHERE c1 IS NULL OR c2 IS NULL OR c3 IS NULL
A somewhat less efficient approach that avoids this is below though.
;WITH xmlnamespaces('http://www.w3.org/2001/XMLSchema-instance' AS ns) 
SELECT * 
FROM   YourTable AS T1 
WHERE (
    SELECT T1.* 
    FOR XML PATH('row'), ELEMENTS XSINIL, TYPE
  ).exist('//*/@ns:nil') = 1

Source: link

Recent Questions on sql

    Programming Languages