Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MS SQL if condition

Posted on 2006-11-20
4
Medium Priority
?
10,010 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
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 1500 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

Independent Software Vendors: 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!

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

971 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