[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SQL Query - Select Statement Help

Posted on 2013-05-30
9
Medium Priority
?
503 Views
Last Modified: 2013-05-30
Good Day Experts!

I am having what seems to be a very straightforward issue but I cannot figure it out!

I am getting results as expected from this Select statement...about 35000 records with [Audit Reason 3] values being NULL:

Select
     [Audit Reason 3],*
from
     [Processing Table]
Where
    [Process Week] > '5/1/2013'

I have added to this to only include records where [Audit Reason 3] <> 'Import History'. So I have this Select statement:

Select
     [Audit Reason 3],*
from
     [Processing Table]
Where
    [Process Week] > '5/1/2013' and [Audit Reason 3] <> 'Import History'

NOW, I get no records!  I can't figure out why [Audit Reason 3] <> 'Import History' is now causing no records to show.

Can you help?

Thanks,
jimbo99999
0
Comment
Question by:Jimbo99999
[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
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 41

Expert Comment

by:ralmada
ID: 39207951
maybe some trailing spaces?

rtrim([Audit Reason 3]) <> 'Import History'

or using like

[Audit Reason 3] not like 'Import History%'
0
 
LVL 7

Assisted Solution

by:Ross Turner
Ross Turner earned 200 total points
ID: 39207953
Hi Jimbo

[Process Week]  is this a datetime datatype ?

anyway try this

SELECT [Audit Reason 3],*
FROM [Processing Table]
WHERE [Process Week] > '20130105'
AND [Audit Reason 3] not like 'Import History'

Open in new window

0
 
LVL 13

Assisted Solution

by:Philip Pinnell
Philip Pinnell earned 200 total points
ID: 39207957
Try

SELECT [Audit Reason 3],*
FROM [Processing Table]
WHERE [Process Week] > '20130105'
AND isnull([Audit Reason 3],'') not like '%Import History%'
0
Technology Partners: 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!

 

Author Comment

by:Jimbo99999
ID: 39207973
I just checked and the DataType is varchar.  I will try the trailing spaces idea...thanks, I did not even think down that road.
0
 

Author Comment

by:Jimbo99999
ID: 39208129
I tried the following and received no records returned:

rtrim([Audit Reason 3]) <> 'Import History'
[Audit Reason 3] not like 'Import History%'
[Audit Reason 3] not like 'Import History'

I tried the following and it worked:

isnull([Audit Reason 3],'') not like '%Import History%'

Ok, problem is I do not understand why it worked and the others didn't!  I mean NULL is <> 'Import History' so I guess that is where I am confused.

jimbo99999
0
 
LVL 41

Accepted Solution

by:
ralmada earned 1600 total points
ID: 39208147
Ok, In that case I would use the following, as this will improve performance:

.... AND ([Audit Reason 3] is null or [Audit Reason 3] not like 'Import History%')

This will help you understand why it didn't work:

http://weblogs.sqlteam.com/markc/archive/2009/06/08/60929.aspx
0
 
LVL 41

Expert Comment

by:ralmada
ID: 39208177
And now that I'm thinking, I guess you don't even have a trailing spaces problem. So I would just do

Select
     [Audit Reason 3],*
from
     [Processing Table]
Where
    [Process Week] > '5/1/2013' and ([Audit Reason 3] <> 'Import History' or [Audit Reason 3] is null)
0
 

Author Closing Comment

by:Jimbo99999
ID: 39208437
Thank you all for your repsonses. I have archived all for future reference.

Have a good day,
jimbo99999
0
 
LVL 13

Expert Comment

by:Philip Pinnell
ID: 39210014
Thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

656 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