Solved

SQL Null not returning results

Posted on 2008-06-10
6
196 Views
Last Modified: 2010-03-20
Ok I am writing a very simple statement but I must be missing something...

select accountidname, tsp_srvc_equipmentididname from incident
where subjectidname='turf equipment' and statecode=0

The above statement returns all the values I expect (results are posted below in the CODE SNIPPET).

However, when I run the same query but wanting to show only the results where tsp_srvc_equipmentididname is null

select accountidname, tsp_srvc_equipmentididname from incident
where subjectidname='turf equipment' and statecode=0 and tsp_srvc_equipmentididname='null'

I get NOTHING returned.


CAROLINA LAKES GOLF CLUB, LLC	062704.JTE
CAROLINA LAKES GOLF CLUB, LLC	NULL
FIRETHORNE GC	NULL
WILSON COUNTRY CLUB	NULL
THE GOLF CLUB AT STAR FORT, INC.	NULL
GAFFNEY CC	NULL

Open in new window

0
Comment
Question by:r270ba
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
NIMTUG_Simon earned 500 total points
ID: 21754039
Try tsp_srvc_equipmentididname is NULL

(No quotes around the NULL and replace = with IS)
0
 
LVL 3

Expert Comment

by:NIMTUG_Simon
ID: 21754052

select accountidname, tsp_srvc_equipmentididname from incident
where subjectidname='turf equipment' and statecode=0 and tsp_srvc_equipmentididname IS NULL

Open in new window

0
 

Author Comment

by:r270ba
ID: 21754063
Perfect...I knew I was missing something easy...I was doing ='null' and isnull and = null but I did not know to put a space between is and null :).

Thanks!
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21754064
NULL is special:
select accountidname, tsp_srvc_equipmentididname from incident
where subjectidname='turf equipment' and statecode=0 and tsp_srvc_equipmentididname IS NULL

Open in new window

0
 
LVL 3

Expert Comment

by:NIMTUG_Simon
ID: 21757175
ISNULL is actually a function which you can use to replace the value with a set value is the original value is null.

So if you have a table (t1) with

col1
=====
'A'
'B'
NULL
'C'

you can have a query which goes

Select ISNULL(col1, 'No Value') as col1 FROM t1

You will get

'A'
'B'
'No Value'
'C'
0
 

Author Comment

by:r270ba
ID: 21760068
sweet...thanks a lot guys!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sql Stored Procedure field variable 17 36
Need help how to find where my error is in UFD 6 40
sql server query 12 25
Parse this column 6 27
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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