Null and zero string

  • I ran a script below but some blank records are still showing up.

    What is wrong?

    AttachmentKey is varchar(175)

    SELECT AttachmentKey

    FROM dbo.order

    WHERE (NOT (AttachmentKey IS NULL)) OR

    (AttachmentKey <> ' ')

  • Looking at the following, if AttachmentKey is '', then AttachmentKey IS NULL is false, which then becomes true due to the NOT which makes this part of the WHERE clause true allowing the '' to pass through.

    (NOT (AttachmentKey IS NULL)) OR (AttachmentKey <> ' ')

  • Try either of these:

    SELECT AttachmentKey

    FROM dbo.order

    WHERE NOT( (AttachmentKey IS NULL)) OR (AttachmentKey = '') )

    OR

    SELECT AttachmentKey

    FROM dbo.order

    WHERE (AttachmentKey IS NOT NULL) AND (AttachmentKey <> '')

  • adonetok (2/19/2013)


    I ran a script below but some blank records are still showing up.

    What is wrong?

    AttachmentKey is varchar(175)

    SELECT AttachmentKey

    FROM dbo.order

    WHERE (NOT (AttachmentKey IS NULL)) OR

    (AttachmentKey <> ' ')

    Is this what you're trying to do?

    SELECT AttachmentKey

    FROM dbo.order

    WHERE NULLIF(AttachmentKey , '') IS NOT NULL

    ---------------------------------------------------------

    It takes a minimal capacity for rational thought to see that the corporate 'free press' is a structurally irrational and biased, and extremely violent, system of elite propaganda.
    David Edwards - Media lens[/url]

    Society has varying and conflicting interests; what is called objectivity is the disguise of one of these interests - that of neutrality. But neutrality is a fiction in an unneutral world. There are victims, there are executioners, and there are bystanders... and the 'objectivity' of the bystander calls for inaction while other heads fall.
    Howard Zinn

  • Thank you for help.

    Finally, the scripts below will get right result:

    WHERE (AttachmentKey <> ' ')

    WHERE (AttachmentKey IS NOT NULL) AND (AttachmentKey <> '')

    WHERE NULLIF(AttachmentKey , '') IS NOT NULL

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply