Solved

delphi 3

Posted on 2013-06-22
5
244 Views
Last Modified: 2013-07-09
I have two implement below logic,

case function of
1 : Showmessage ('1');
2: Showmessage('2');
3: showmessage('3');

function in above statement shall return 1 or 2 or 3 querying a table on below conditions:

The table has two columns eg A and B, which contain either 0 or 1 values.
First condition shall be querying the table where column B has all 0 values. For this condition the function shall return 1.
Second condition:  Column B has all 1 values and column A has 0 values. For this condition the function shall return 2.
Third condition: Column B has all 1 values and Column A has 1 values, for this condition the function shall returen 3.

Need help with code snippet !
0
Comment
Question by:AbhiJeet
[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
  • 2
5 Comments
 
LVL 24

Accepted Solution

by:
jimyX earned 500 total points
ID: 39268314
Here is a query that detects your three conditions and returns either 1, 2 or 3, and in case of other order it returns negative:
function CaseResultZeroOne():integer;
begin
  with AdoQry do
    begin
      Close;
      Sql.Clear;
      Sql.Add('select (case Sum(b) when 0 then 1 else');
      Sql.Add('case when (Sum(b) = Count(b)) and (Sum(a) = 0) then 2 else');
      Sql.Add('case when (Sum(a) = Count(a)) and (Sum(b) = Count(b)) then 3 else -2 end end end) AS CaseResult');
      Sql.Add('from DBTable;');
      Open;
      if IsEmpty then
        Result := -1
      else
        Result := FieldByName('CaseResult').AsInteger;
      Close;
    end;
end;

...

case CaseResultZeroOne() of
  1 : Showmessage ('1');
  2: Showmessage('2');
  3: showmessage('3');
end;

Open in new window


Assuming your table name is "DBTable".
What happens if your conditions are not met?
For instance, if column A is not all ones but column B is all ones?
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 39268625
this is an abstract sample of a problem
as jimyX pointed out, the else condition is missing
or the equation of your abstract problem is not complete
0
 

Author Comment

by:AbhiJeet
ID: 39269039
any other nice and simple work around?
0
 
LVL 24

Expert Comment

by:jimyX
ID: 39269189
It involves DB and records, no other work around.
The only way to do that is to read the records from the database so that's the best that it could be.

Probably you can explain, what did you expect the solution to look like.
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 39269907
from a quote: "nulls are evil"
from the text of your question: either 0 or 1 values

what do you understand as 0 values
> the column has all values as zero (or 0)
> the column has all nulls (or 0 values)

your question contains ambiguities and because of that it's unclear what you want
> you'll have to explain in more detail what you want
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Firemonkey webbrowser scrollbars ? 1 69
Firemonkey android show image from resource ? 1 71
Delphi...Split view - idea? 1 145
Twebbrowser add css to the header 3 53
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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