You can use RegEx-like condition, however the supported functionality is very limited in native T-SQL.
SELECT
MEMO_SYSTEM_TXT
FROM
[EE].[dbo].[EE_Billing_Memo]
WHERE
MEMO_SYSTEM_TXT LIKE N'%[^ ]%'
Example values
SELECT
*
FROM
(VALUES (''), (' '), (' '), ('x y'), (' x'), ('x ')) AS A(txt)
WHERE
txt LIKE N'%[^ ]%'
If this is not a on-time query, update the data stored in the column, update all records to remove all space-only values (update them to NULL or empty string).
You can add a CHECK
constraint for the column to prevent newly created 'empty' records.
Updating all 'empyt' values to NULL
UPDATE
[EE].[dbo].[EE_Billing_Memo]
SET
MEMO_SYSTEM_TXT = NULL
WHERE
MEMO_SYSTEM_TXT LIKE N'%[^ ]%'
The CHECK
constraint to add:
CONSTRAINT CK_PreventEmpty_MEMO_SYSTEM_TXT
CHECK MEMO_SYSTEM_TXT LIKE N'%[^ ]%'
An alternative solution is to add an INSTEAD OF
trigger (INSERT
and UPDATE
) to prevent 'empty' values in MEMO_SYSTEM_TXT
, OR you can create an indexed view which is not contains the 'empty' texts.