Solved

Simple SQL Query Problem

Posted on 2012-04-02
6
283 Views
Last Modified: 2012-06-27
What is wrong in this query? :-)


Row:
wid = 70073, wcat = NULL


SELECT  wid, wcat FROM watches WHERE wid = 70073
1 row affected


SELECT  wid, wcat FROM watches WHERE wcat != 'o' AND wid = 70073
0 rows affected

See also screenshots attached.
sql01.png
sql02.png
0
Comment
Question by:lukasfrei
6 Comments
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
Change it to

Wcat IS NULL
0
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
Ignore my last post.
0
 
LVL 9

Accepted Solution

by:
mimran18 earned 500 total points
Comment Utility
Here we go,

SELECT  wid, wcat FROM watches WHERE ISNULL(wcat,'') != 'o' AND wid = 70073
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 39

Expert Comment

by:Pratima Pharande
Comment Utility
what is datatype of wcat

try

SELECT  wid, wcat FROM watches WHERE wcat <> 'o' AND wid = 70073

or

SELECT  wid, wcat FROM watches WHERE wcat not like  'o' AND wid = 70073
0
 
LVL 7

Expert Comment

by:waltersnowslinarnold
Comment Utility
You should handle NULL properly, NULL is always a trouble maker;

Use the below sample, this should help you;

SELECT  wid, wcat FROM watches WHERE ISNULL(wcat,'') != 'o' AND wid = 70073

OR

SELECT  wid, wcat FROM watches WHERE ISNULL(wcat,'') <> 'o' AND wid = 70073
0
 

Author Closing Comment

by:lukasfrei
Comment Utility
wow, thanks for help to all of you
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

763 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

10 Experts available now in Live!

Get 1:1 Help Now