Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MS SQL if condition

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

661 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