Solved

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

Posted on 2010-11-16
3
342 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
  • 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
OPENDATASOURCE 8 31
combine data in sql 1 29
sql sERVER PARSE DATA BY HOURS AND COLUMNS 2 31
SQL Encryption question 2 42
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now