Link to home
Start Free TrialLog in
Avatar of Coloplast
ColoplastFlag for Denmark

asked on

SQL simple query

I have a table with 6 columns.
I would like the query to return rows where column 4 and 6 IS NOT NULL at the same time.
Can you help with a query?
Thanks
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

try:

select * from yourTable where column4 is not null and column6 is not null
Avatar of Coloplast

ASKER

Tried that but it still gives me rows with NULL i both columns
>>Tried that but it still gives me rows with NULL i both columns
are you sure that?

if you got blank values in one of those columns, it's a blank value NOT a NULL value.
do you want to return those records with blank values in either column4 or column6 ?
If there is a NULL value in both 4 and 6 I don't want it returned
>>If there is a NULL value in both 4 and 6 I don't want it returned

so both must be not NULL, if yes, then try my previous posted SQL:

select * from yourTable where column4 is not null AND column6 is not null

IF either column4 or column6 contains NULL value and want to exclude them, try:

select * from yourTable where column4 is not null OR column6 is not null
I ran this query:
SELECT [ID]
      ,[Fornavn]
      ,[Efternavn]
      ,[Initialer]
      ,[Løn Nummer]
      ,[Kortnummer]
      ,[GammelIDKort]
  FROM [Cardexchange].[dbo].[users]
  WHERE ('Løn nummer' IS NOT NULL) AND ('GammelIDKort' IS NOT NULL)

Open in new window


And I get the following returned:
User generated image
ASKER CERTIFIED SOLUTION
Avatar of Vikas Garg
Vikas Garg
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Vikas is correct on that.

'Løn nummer' would be referring to a char value, NOT referring to a field name.
:)

'Løn nummer' is a string
[Løn nummer] or "Løn nummer" refers to the column
as an observation, it seems that Ryan Chong provided the correct advice yet is unrewarded