Solved

MS SQL if condition

Posted on 2006-11-20
4
9,999 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
[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
4 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 17980759
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
ID: 17980766
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
ID: 17980931
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

622 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