Solved

Figure out which rows DO NOT contain a value

Posted on 2013-01-25
4
217 Views
Last Modified: 2013-01-25
I have a query that shows me a result set of documents that are attached to Orders within my system.  I need to be able to filter this result set and base the logic to see which ones DO NOT have a DocTypeID of 'WorkTick'

What I'm attempting to do is figure out which Orders do not have a work ticket associated basically this way I can create a report to show which orders don't have tickets but there are various document types so I'm a little confused on the best and most efficient means of doing so?  Its almost like I have to build the result set, and THEN loop through that result set to see which ones do or do not.  At least thats what I see at first glance.

Any help is VERY much appreciated and I will promptly respond and accept an answer

SELECT * FROM eDocData ORDER BY OrderNum DESC

The result set looks like so:

OrderNum      DocTypeID
87673                       NULL
87651                       DispTick
87625                       NULL
87622                       NULL
87550                       DispTick
87549                       WorkTick
87549                       DispTick
87546                      WorkTick
87546                      DispTick
87541                      NULL
0
Comment
Question by:chrisryhal
4 Comments
 
LVL 6

Accepted Solution

by:
liija earned 167 total points
ID: 38820286
Can it be this simple?

SELECT * FROM eDocData
WHERE DocTypeID <> 'WorkTick'
 OR DocTypeID IS NULL
0
 

Assisted Solution

by:britpopfan74
britpopfan74 earned 167 total points
ID: 38820289
If I'm understanding correctly, only those with 'WorkTick' are valid work orders and all others are not?

If so, it could just be:

SELECT * FROM eDocData
WHERE DocTypeID = 'WorkTick'
ORDER BY OrderNum DESC
0
 
LVL 11

Assisted Solution

by:Simone B
Simone B earned 166 total points
ID: 38820290
You could try a subquery:

Select * from eDocData where OrderNum not in
(Select OrderNum from eDocData where doctypeid = 'WorkTick')
0
 
LVL 2

Author Closing Comment

by:chrisryhal
ID: 38820435
I feel really dumb, but yes it was that easy (GRIN)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

792 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