?
Solved

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

Posted on 2010-11-16
3
Medium Priority
?
384 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

There are some very powerful Dynamic Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a di…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

650 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