473,761 Members | 6,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't get "<>" (not equals) to work in view

I'm having problems using "<>" as criteria for a varchar column in a
view. The data in this column is '2008-2009' which is supposed to
mean year 2008 thru 2009. If I set the criteria to "= '2008-2009'"
then the view returns just those rows with that field equal to
"2008-2009", like I would expect it to. But if I change the criteria
to "<'2008-2009'", the view returns nothing. And there are rows to
return. I tried CAST and CONVERT, thinking the view was interpreting
the criteria as numbers, but that didn't help. I tried both
CAST('2008-2009' AS varchar(9)) and CONVERT(varchar (9), '2008-2009').
Both would work with "=" but not with "<>".

I tried using "<>" on another column in the table and it worked fine.
This was a "last name" column so there weren't any numbers.

Any help or advice appreciated.
Oct 29 '08 #1
4 3509
On Wed, 29 Oct 2008 14:49:05 -0700 (PDT), em******@kumc.e du wrote:
>I'm having problems using "<>" as criteria for a varchar column in a
view. The data in this column is '2008-2009' which is supposed to
mean year 2008 thru 2009. If I set the criteria to "= '2008-2009'"
then the view returns just those rows with that field equal to
"2008-2009", like I would expect it to. But if I change the criteria
to "<'2008-2009'", the view returns nothing. And there are rows to
return. I tried CAST and CONVERT, thinking the view was interpreting
the criteria as numbers, but that didn't help. I tried both
CAST('2008-2009' AS varchar(9)) and CONVERT(varchar (9), '2008-2009').
Both would work with "=" but not with "<>".

I tried using "<>" on another column in the table and it worked fine.
This was a "last name" column so there weren't any numbers.

Any help or advice appreciated.
Hi emanning,

Please post table structure (as a CREATE TABLE statement), some sample
data (as INSERT statements), the definition of your view (as a CREATE
VIEW statement), the query you are using to test, the data you got
returned and the data you expected to get.

Based on your description I can only conclude that either you overlooked
some seemingly minor detail that affects your results, or you ran into a
bug - and I consider the former to be more probable than the latter.

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Oct 29 '08 #2
(em******@kumc. edu) writes:
I'm having problems using "<>" as criteria for a varchar column in a
view. The data in this column is '2008-2009' which is supposed to
mean year 2008 thru 2009. If I set the criteria to "= '2008-2009'"
then the view returns just those rows with that field equal to
"2008-2009", like I would expect it to. But if I change the criteria
to "<'2008-2009'", the view returns nothing. And there are rows to
return. I tried CAST and CONVERT, thinking the view was interpreting
the criteria as numbers, but that didn't help. I tried both
CAST('2008-2009' AS varchar(9)) and CONVERT(varchar (9), '2008-2009').
Both would work with "=" but not with "<>".
Keep in mind that if there are rows with NULL in this column, they will
not be returned with <>, because NULL represents an unknown value, so we
don't know whether it unequal to '2008-2009'.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Oct 29 '08 #3
On Oct 29, 5:43*pm, Erland Sommarskog <esq...@sommars kog.sewrote:
*(emann...@kumc .edu) writes:
I'm having problems using "<>" as criteria for a varchar column in a
view. *The data in this column is '2008-2009' which is supposed to
mean year 2008 thru 2009. *If I set the criteria to "= '2008-2009'"
then the view returns just those rows with that field equal to
"2008-2009", like I would expect it to. *But if I change the criteria
to "<'2008-2009'", the view returns nothing. *And there are rows to
return. *I tried CAST and CONVERT, thinking the view was interpreting
the criteria as numbers, but that didn't help. *I tried both
CAST('2008-2009' AS varchar(9)) and CONVERT(varchar (9), '2008-2009').
Both would work with "=" but not with "<>".

Keep in mind that if there are rows with NULL in this column, they will
not be returned with <>, because NULL represents an unknown value, so we
don't know whether it unequal to '2008-2009'.

--
Erland Sommarskog, SQL Server MVP, esq...@sommarsk og.se

Links for SQL Server Books Online:
SQL 2008:http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005:http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000:http://www.microsoft.com/sql/prodinf...ons/books.mspx
By adding "OR <column nameIS NULL" to the criteria statement solved
the problem. Thanks for your help.
Oct 30 '08 #4
On Oct 30, 9:37*am, emann...@kumc.e du wrote:
By adding "OR <column nameIS NULL" to the criteria statement solved
the problem. *Thanks for your help.
Hi emanning,

You might try using this:
AND COALESCE(col_na me,'') <'2008-2009'

Instead of this:
AND (col_name <'2008-2009 OR col_name IS NULL)

Depending on the complexity of the view definition, and the size of
the base table, you may find that COALESCE offers better performance
than using an OR...IS NULL
Oct 30 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
3351
by: Dr Duck | last post by:
GDay all, Something seems odd to me.... I wrote a simple C# function public void bind(ref object a, ref object b, bool atob) { if(atob) b = a; else
2
15950
by: ESPNSTI | last post by:
Hi, I'm trying to use a generics dictionary with a key class that implements and needs IComparable<>. However when I attempt to use the dictionary, it doesn't appear to use the IComparable<> to find the key. In the example below, accessing the dictionary by using the exact key object that was used to add to the dictionary works. (see code comment 1). However, if I attempt to access the dictionary by using a key object that
8
1365
by: active | last post by:
I use quickwatch on (astrThisOne <> "") and it reports: False as it should because astrThisOne reports: "" Yet If (astrThisOne <> "") Then executes the Then clause
4
1557
by: Rich | last post by:
Hello, Just checking which is more efficient/better/or correct Do While something str1 = dr(i).ToString If Not str1.Equals("xyz") Then .... or
16
9188
by: network-admin | last post by:
We have Problems with Access query on Oracle 10g Database with ODBC Connection. The Query_1 is such as select * from xtable where ycolumn <"S" Result = ODBC Faild ----------------------------------------------------
4
1427
by: Ed | last post by:
Hi, guys, Here is a simple template class definition: template <typename T = int> class Point { public: T X; T Y; T Z; };
0
10111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9948
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7327
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6603
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.