Solved

where not in ( int value and null)

Posted on 2011-02-16
8
281 Views
Last Modified: 2012-05-11
statusfk is supposed to be null or have an int value that is 8 numbers. but i saw in the table there is one with 7 digits.

but the following query
select * from tblsinger where len(statusfk) not in (8, null)
did not bring back the records for statusfk with 7 length.

what is wrong with the query?

thanks
0
Comment
Question by:anushahanna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 167 total points
ID: 34910332
NOT IN + NULL = bad query

NULL is not comparable to anything, so if it is present in the NOT IN clause at all, it is as good as filtering everything out.
0
 
LVL 9

Assisted Solution

by:AriMc
AriMc earned 83 total points
ID: 34910350
LEN function works on character fields only. For integers you could try:

select * from tblsinger where statusfk between (1000000 and 9999999)

0
 
LVL 50

Assisted Solution

by:Lowfatspread
Lowfatspread earned 167 total points
ID: 34910352
1 you can only test a column against null with the IS NULL/IS NOT NULL SYNTAX
2  a null value "doesn't" have a length
3 len is for character columns only

so try

select * from tblsinger
 where statusfk < 10000000
 
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 6

Author Comment

by:anushahanna
ID: 34910429
>>NOT IN + NULL = bad query
>>you can only test a column against null with the IS NULL/IS NOT NULL SYNTAX

THANK YOU....

now,
select * from tblsinger where statusfk is not null and len(statusfk)<8
worked
(len does work for int - can you please test that)
0
 
LVL 41

Assisted Solution

by:Sharath
Sharath earned 83 total points
ID: 34910918
Yes, you can check the no. of digits with LEN.
0
 
LVL 50

Assisted Solution

by:Lowfatspread
Lowfatspread earned 167 total points
ID: 34911110
you can "check" with len on the size of the converted string... from the underlying numeric data type

if the statusfk is indexed then the len(statusfk) check makes it non sargable  (less likely to use an index efficiently)

where as the numeric range condition does not suffer from that problem...

in the general case you may want to consider the effect of negative numbers as well
0
 
LVL 58

Assisted Solution

by:cyberkiwi
cyberkiwi earned 167 total points
ID: 34912850
@AriMC "LEN function works on character fields only. For integers you could try:"
@Lowfatspread

Try select LEN(1234), LEN(1234222)

> have an int value that is 8 numbers

So Len( ) does work to flush it out.

@Lowfatspread

While you are right about performance, the question is worded as a one-off so by the time you posted that tidbit, the problem has been solved...
0
 
LVL 6

Author Comment

by:anushahanna
ID: 34917557
thanks for your helpful explanation.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
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.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

705 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