Solved

T-SQL: Why does "select null or 1" elicit a syntax error?

Posted on 2010-11-16
3
368 Views
Last Modified: 2012-08-13
I'm trying to manually test to see if part of my WHERE clause will work correctly:
... and (ColA=1 or ColB is null) ...
and it's likely that ColA will be null.

Question: HOW can I test this MANUALLY "at the console" with a simple select statement?

I tried something like this and doesn't work... it returns a syntax error:
select null or 1
to illustrate ColA being null and ColB NOT being null.   I want to "prove" this will evaluate TRUE (null or TRUE => TRUE).
0
Comment
Question by:ZuZuPetals
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 34151111
this is a query that tests your condition (mock)

select 1
where (null = 1 or 1 is null)

here if the where condition is true it returns 1 otherwise no result
see cola replaced by null and colb by 1
0
 
LVL 2

Author Comment

by:ZuZuPetals
ID: 34151152
Ah, that helps.  I was trying to do my "console" statement in the same form as
select 2+2
Guess that's not valid SQL!
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34151216
select 2+2 does work
But
select (null=1)
for example is hanging.. it returns a condition, but what is it doing with it?
So we make a where clause out of it
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question