• Beatrix Kiddo (5/1/2013)


    I know this is a popular one and I've Googled it but I haven't found anything that has worked yet, so apologies if this is incredibly obvious.

    I'm trying to amend a view to exclude records that are either null or blank in a field called CURRENT_POINT

    ...

    and CURRENT_POINT is not null

    and DATALENGTH(CURRENT_POINT)> 0

    The nulls are fine, but I'm still getting the blanks. I hoped DATALENGTH would resolve that but it hasn't.

    As I said, I'm sorry if it's obvious. Can anybody advise me please?

    Here's a little test harness to see what DATALENGTH returns with different values:

    SELECT

    CURRENT_POINT,

    [LEN] = LEN(CURRENT_POINT),

    [DATALENGTH] = DATALENGTH(CURRENT_POINT)

    FROM (

    SELECT rn = 1, CURRENT_POINT = CAST(' ' AS VARCHAR(15)) UNION ALL

    SELECT 2, SPACE(3) UNION ALL

    SELECT 3, NULL UNION ALL

    SELECT 4, '' UNION ALL

    SELECT 5, 'Something here'

    ) d

    WHERE 1 = 1

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden