Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting records which have two fields NULL or empty

Status
Not open for further replies.

kwirky

MIS
Apr 22, 2010
85
AU
Hi,
I am trying to create a select query which will show me only the records which have a value in 2 fields. I have tried the below and it seems to work okay except that i am still getting some records which have an 'empty' Text17. In the example below I do not expect to see the 2nd and 3rd record. (there are 4 columns here, RAM_PROCESS_CTR; RAM_ID; TEXT16; TEXT17 and the values in Text16 and Text17 will be numerical, record 1 & 4 have the values 1 & 2 in text16 + text17 and records 2 & 3 have only value 1 in text16)


RAM_PROCESS_CTR | RAM_ID | TEXT16 | TEXT17
255029 | RPP00476 | 1 | 2
255030 | RPP00477 | 1 |
255031 | RPP00478 | 1 |
255032 | RPP00479 | 1 | 2

Script:
SELECT [RAM_PROCESS_CTR]
,[RAM_ID]
,[TEXT16]
,[TEXT17]
FROM [probeta].[dbo].[RAMAPPLICATIONPROCESS]
Where RAM_ID like 'RPP%' and
STATUS = 'C' and
((
TEXT16 IS NOT NULL or
TEXT16 <> ''
)
and
(
TEXT17 IS NOT NULL or
TEXT17 <> ''
))

I have not been able to figure out what I am doing wrong here. Any help would be appreciated.

Thank you
 
Change OR to AND:
Code:
(
(TEXT16 IS NOT NULL AND TEXT16 <> '')
and
(TEXT17 IS NOT NULL AND TEXT17 <> '')
)

Borislav Borissov
VFP9 SP2, SQL Server
 
Alternatively, you could use this...

Code:
Where Text16 > '' And Text17 > ''

If the value is NULL, it will not be returned, and if the value is an empty string it will also not be returned.

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thank you so much for your help.

I used George's

Where Text16 > '' And Text17 > ''

and it worked beautifully.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top