Solved

Figure out which rows DO NOT contain a value

Posted on 2013-01-25
4
214 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now