Solved

MS SQL if condition

Posted on 2006-11-20
4
9,935 Views
Last Modified: 2011-08-18
I have the following query:

select a.file_job, Cntr=count(cont_num), CntrOut=count(date_out), CntrIn=count(date_in), Status=''
from cargodetailcontainer a join  cargodetail b on a.file_job=b.file_job
group by a.file_job
order by a.file_job
      
If all three column value is equle (Cntr=count(cont_num), CntrOut=count(date_out), CntrIn=count(date_in)) then on status (last cloumn) I have to show "Closed" else "Open"

Please help

Rgds.
0
Comment
Question by:Mehram
  • 2
4 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
Comment Utility
Try it this way:

select a.file_job, count(cont_num) CNTR, count(date_out) CNTR_OUT, count(date_in) CNTR_IN, When (CNTR = CNTR_OUT AND CNTR = CNTR_IN then "Closed" ELSE "Open" END) Status
from cargodetailcontainer a join  cargodetail b on a.file_job=b.file_job
group by a.file_job
order by a.file_job

AW
0
 
LVL 29

Accepted Solution

by:
Nightman earned 500 total points
Comment Utility
Try this:

select a.file_job, Cntr=count(cont_num), CntrOut=count(date_out), CntrIn=count(date_in),
CASE count(cont_num) WHEN  count(date_out) | count(date_in) THEN 'Closed' ELSE 'Open' END Status
from cargodetailcontainer a join  cargodetail b on a.file_job=b.file_job
group by a.file_job
order by a.file_job
0
 
LVL 29

Expert Comment

by:Nightman
Comment Utility
Mehram, I am glad that I was able to assist you so quickly. However, I am at a loss to understand why you gave me such a low grade. A C is the lowest grade you can give. Please can you explain this.

Also, please see http://www.experts-exchange.com/help.jsp#hi73 - "What's the right grade to give".
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

12 Experts available now in Live!

Get 1:1 Help Now