I need to write a sql query that filters out rows that have a changing number of spaces in a field. For example, I have this query
SELECT MEMO_SYSTEM_TXT
FROM [EE].[dbo].[EE_Billing_Memo]
where MEMO_SYSTEM_TXT is not null and MEMO_SYSTEM_TXT <> '' and MEMO_SYSTEM_TXT <> ' '
I found out that the field MEMO_SYSTEM_TXT might contain different number of spaces, so my restrictions are not sufficient. Anyone have a robust where cluase that will filter out all spaces at once ?
SELECT
MEMO_SYSTEM_TXT
FROM [EE].[dbo].[EE_Billing_Memo]
WHERE
MEMO_SYSTEM_TXT IS NOT NULL
AND LTRIM(MEMO_SYSTEM_TXT) <> ''
several spaces will always equal empty string
SELECT 1
WHERE
'a' = 'a ' and
'a' = 'a ' and
'' = ' ' and
cast('' as char(1)) = cast(' ' as char(5))
Returns 1 since they are all equal
So all you have to do is this:
SELECT MEMO_SYSTEM_TXT
FROM [EE].[dbo].[EE_Billing_Memo]
WHERE MEMO_SYSTEM_TXT is not null and MEMO_SYSTEM_TXT <> ''
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With