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
ColoplastAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
try:

select * from yourTable where column4 is not null and column6 is not null
0
ColoplastAuthor Commented:
Tried that but it still gives me rows with NULL i both columns
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
>>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.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
do you want to return those records with blank values in either column4 or column6 ?
0
ColoplastAuthor Commented:
If there is a NULL value in both 4 and 6 I don't want it returned
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
>>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
0
ColoplastAuthor Commented:
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:
I still get rows where 'Løn nummer' and 'GammelIDKort' is NULL, why?
0
Vikas GargBusiness Intelligence DeveloperCommented:
HI,

Run this

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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
Vikas is correct on that.

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

'Løn nummer' is a string
[Løn nummer] or "Løn nummer" refers to the column
0
PortletPaulfreelancerCommented:
as an observation, it seems that Ryan Chong provided the correct advice yet is unrewarded
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.