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. 4 3473
On Wed, 29 Oct 2008 14:49:05 -0700 (PDT), em******@kumc.edu 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
(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****@sommarskog.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
On Oct 29, 5:43*pm, Erland Sommarskog <esq...@sommarskog.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...@sommarskog.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.
On Oct 30, 9:37*am, emann...@kumc.edu 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_name,'') <'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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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
|
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...
|
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
|
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
|
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...
|
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;
};
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |