This SSRS expression gets me what I need:
=CountDistinct(IIF(Fields!BuildingNumber.Value = "1" AND Fields!InspectionCycle.Value ="A" OR Fields!InspectionCycle.Value ="B" ,Fields!ParcelID.Value,Nothing), "DataSet1")
-CountDistinct(IIF(Fields!BuildingNumber.Value = "1" AND Fields!InspectionCycle.Value ="A" ,Fields!ParcelID.Value,Nothing), "DataSet1")
I wish to add this condition to the start of it:
=IIF(Parameters!Cycle.Value(0)="A"
And I assume I need to add something like this to the end:
,Nothing), "DataSet1")
I would like to then continue with:
OR =IIF(Parameters!Cycle.Value(0)="B"
I am getting a ')' expected error. Also, is the (0)necessary in the condition? Thank you for your time!
Based on your help here is a working expression:
=IIF(INSTR(JOIN(Parameters!Cycle.Value, ","), "B") > 0, CountDistinct(IIF(Fields!BuildingNumber.Value = "1" AND Fields!InspectionCycle.Value ="B" OR Fields!InspectionCycle.Value ="A" ,Fields!ParcelID.Value,0), "NRBuildingsInsp")-CountDistinct(IIF(Fields!BuildingNumber.Value = "1" AND Fields!InspectionCycle.Value ="A" ,Fields!ParcelID.Value,0), "NRBuildingsInsp"),0)
And here it checks another parameter if the first is false:
=IIF(INSTR(JOIN(Parameters!Cycle.Value, ","), "B") > 0, CountDistinct(IIF(Fields!BuildingNumber.Value = "1" AND Fields!InspectionCycle.Value ="B" OR Fields!InspectionCycle.Value ="A" ,Fields!ParcelID.Value,0), "NRBuildingsInsp")-CountDistinct(IIF(Fields!BuildingNumber.Value = "1" AND Fields!InspectionCycle.Value ="A" ,Fields!ParcelID.Value,0), "NRBuildingsInsp"),IIF(INSTR(JOIN(Parameters!Cycle.Value, ","), "C") > 0, CountDistinct(IIF(Fields!BuildingNumber.Value = "1" AND Fields!InspectionCycle.Value ="C" OR Fields!InspectionCycle.Value ="A" ,Fields!ParcelID.Value,0), "NRBuildingsInsp")-CountDistinct(IIF(Fields!BuildingNumber.Value = "1" AND Fields!InspectionCycle.Value ="A" ,Fields!ParcelID.Value,0), "NRBuildingsInsp"))
How would I have to modify it to provide results where Parameters!Cycle.Value = both "B" and "C"?
Related
I have been looking through all other mentionings of "MySQL" and "CONCAT_WS" but they do not address my problem. I have a medical database set up in MySQL (5.5.6x) with 180 tables and several thousand fields. The handling of database tables and forms is done through a large PHP application.
Part of my SQL query is the following code:
CONCAT_WS(""
, COALESCE(CASE WHEN op.OP5Begleiteingriff1 = "2" THEN "Cholezystektomie " ELSE CONCAT("", "") END, "NULL")
, COALESCE(CASE WHEN op.OP5Begleiteingriff2 = "2" THEN "Appendektomie " ELSE CONCAT("", "") END, "NULL")
, COALESCE(CASE WHEN op.OP5Begleiteingriff3 = "2" THEN "Adhäsiolyse " ELSE CONCAT("", "") END, "NULL")
, COALESCE(CASE WHEN op.OP5Begleiteingriff4 = "2" THEN "Antrum-Resektion " ELSE CONCAT("", "") END, "NULL")
, COALESCE(CASE WHEN op.OP5Begleiteingriff5 = "2" THEN "Hiatoplastie " ELSE CONCAT("", "") END, "NULL")
, COALESCE(CASE WHEN op.OP5Begleiteingriff6 = "2" THEN "Hernien-Reparatur " ELSE CONCAT("", "") END, "NULL")
, COALESCE(CASE WHEN op.OP5Begleiteingriff7 = "2" THEN "Band-Entfernung " ELSE CONCAT("", "") END, "NULL")
, COALESCE(CASE WHEN op.OP5Begleiteingriff8 = "2" THEN "Fundus-Resektion " ELSE CONCAT("", "") END, "NULL")
, COALESCE(CASE WHEN op.OP5Begleiteingriff9 = "2" THEN "Rest-Gastrektomie " ELSE CONCAT("", "") END, "NULL")
, COALESCE(CASE WHEN op.OP5Begleiteingriff10 = "2" THEN "Leber-Biopsie " ELSE CONCAT("", "") END, "NULL")
, COALESCE(CASE WHEN op.OP5Begleiteingriff99 = "2" THEN "Andere Begleiteingriffe" ELSE CONCAT("", "") END, "NULL")
) AS "Begleiteingriffe (OP 5)",
This denotes the content extraction of the fields
op.OP5Begleiteingriffx = "2"
(= "2" means that the respective checkbox has been clicked) from x equalling -1 to -10 or -99.
Now, I want to limit the display of results to those fields which are not empty.
Is there an elegant way to do this in a short fashion?
So far, I have implemented something like this:
FROM dat_patient p
LEFT OUTER JOIN dat_optherapie op ON op.patID = p.ID
LEFT OUTER JOIN users_benutzer ub ON ub.ID = p.UserID
WHERE op.OP1Datum BETWEEN "1950-01-01" AND "2050-12-31"
AND (
"Begleiteingriffe (OP 1)" != "" OR "Begleiteingriffe (OP 2)" != "" OR "Begleiteingriffe (OP 3)" != "" OR "Begleiteingriffe (OP 4)" != "" OR "Begleiteingriffe (OP 5)" != ""
)
ORDER BY p.Nachname, p.Vorname, p.Gebdatum; ';
It still delivers ALL results and does not omit the empty fields:
Is it possible at all to handle it this way or do I need to set up a handling for every
op.OP5Begleiteingriffx
like in the above-mentioned AND ... statement?
OWN SOLUTION:
It does not work regarding the use of
"Begleiteingriffe (OP 1)" != ""
or
"Begleiteingriffe (OP 1)" IS NOT NULL
but works when every single possibility is handled as such in
WHERE (
op.OP1Begleiteingriff1 = "2" OR
op.OP1Begleiteingriff2 = "2" OR
op.OP1Begleiteingriff3 = "2" OR
op.OP1Begleiteingriff4 = "2" OR
op.OP1Begleiteingriff5 = "2" OR
op.OP1Begleiteingriff6 = "2" OR
op.OP1Begleiteingriff7 = "2" OR
op.OP1Begleiteingriff8 = "2" OR
op.OP1Begleiteingriff9 = "2" OR
op.OP1Begleiteingriff10 = "2" OR
op.OP1Begleiteingriff99 = "2"
)
Now, I only get displayed results where there are no more empty fields:
I think, instead of doing bunch of OR in WHERE, you might try using HAVING. Probably, something like this:
SELECT ....
.....
FROM dat_patient p
LEFT OUTER JOIN dat_optherapie op ON op.patID = p.ID
LEFT OUTER JOIN users_benutzer ub ON ub.ID = p.UserID
WHERE op.OP1Datum BETWEEN "1950-01-01" AND "2050-12-31"
--remove this part
/* AND (
"Begleiteingriffe (OP 1)" != "" OR "Begleiteingriffe (OP 2)" != "" OR "Begleiteingriffe (OP 3)" != "" OR "Begleiteingriffe (OP 4)" != "" OR "Begleiteingriffe (OP 5)" != "" ) */
-- add HAVING here
HAVING "Begleiteingriffe (OP 1)" <> ""
ORDER BY p.Nachname, p.Vorname, p.Gebdatum; ';
Try if this can work.
I'm trying to update some field value depending two string field using a function with If and Case, function below:
Private Function checkDATI(tipotransazione As String, tipovendita As String) As String
Dim r As String
r = ""
If tipotransazione = "VENDITA" Then
Select Case tipovendita
Case "ARMI"
If Me.txtMatricola = "" Then r = "Matricola"
If Me.txtModello = "" Then r = "Modello"
If Me.txtCalibro = "" Then r = "Calibro"
If Me.txtTipoArma = "" Then r = "Tipo Arma"
If Me.txtFabrica = "" Then r = "Fabbrica"
Case "VENDITA ARMI/MUNIZIONI"
Case "MUNIZIONI"
End Select
End If
If tipotransazione = "ACQUISTO" Then
Select Case tipovendita
Case "ARMI"
If Me.txtMatricola = "" Then r = "Matricola"
If Me.txtModello = "" Then r = "Modello"
If Me.txtCalibro = "" Then r = "Calibro"
If Me.txtTipoArma = "" Then r = "Tipo Arma"
If Me.txtFabrica = "" Then r = "Fabbrica"
Case "VENDITA ARMI/MUNIZIONI"
Case "MUNIZIONI"
End Select
End If
checkDATI = r
End Function
And then when I call this function in a command button event as:
MsgBox (checkDATI(Me.CausaleMov, Me.txt_tipomov))
It's not updating that field. What is wrong?
When you say:
If Me.txtMatricola = "" Then r = "Matricola"
What you are doing is assigning the value: "Matricola" to the variable:r. Instead what I think you want is this:
If Me.txtMatricola = "" Then Me.txtMatricola = "Matricola"
This actually sets the value of the field: txtMatricola to "Matricola". This goes for all of the fields that are in your Case statements.
The query below runs quickly when the "FROM" clause has only a single account number (a.account_nbr) and a single object code (a.fin_object_cd), but when I modify the query so that the FROM clause has a range of account numbers and a range of object codes, it takes a VERY long amount of time to return results. It goes from about a minute to run to 20 or more minutes.
The query does return the results I want, but I need to make it run more quickly.
What can I do? I am not sure if adding indexes to some columns would help, or if there's just a better way to write the query.
If you need more information about the tables, or what I'm trying to accomplish, please let me know.
select
a.account_nbr as "Account Number",
a.account_nm as "Account Name",
a.fin_object_cd as "Object Code",
a.fin_obj_cd_nm as "Object Code Name",
(select COALESCE(sum(fin_beg_bal_ln_amt),0) from kfsprd.gl_balance_t where account_nbr = a.account_nbr and fin_object_cd = a.fin_object_cd and univ_fiscal_yr = "2015" and fin_balance_typ_cd != "CB") as "Beginning Balance",
(select COALESCE(sum(trn_ldgr_entr_amt),0) FROM kfsprd.kf_f_transaction_dtl where univ_fiscal_yr = "2015" and account_nbr = a.account_nbr and fin_object_cd = a.fin_object_cd and trn_debit_crdt_cd = "D") as "Debits",
(select COALESCE(sum(trn_ldgr_entr_amt),0) FROM kfsprd.kf_f_transaction_dtl where univ_fiscal_yr = "2015" and account_nbr = a.account_nbr and fin_object_cd = a.fin_object_cd and trn_debit_crdt_cd = "C" and trn_ldgr_entr_amt is not null) as "Credits",
(
(select COALESCE(sum(fin_beg_bal_ln_amt),0) from kfsprd.gl_balance_t where account_nbr = a.account_nbr and fin_object_cd = a.fin_object_cd and univ_fiscal_yr = "2015" and fin_balance_typ_cd != "CB") +
(select COALESCE(sum(trn_ldgr_entr_amt),0) FROM kfsprd.kf_f_transaction_dtl where univ_fiscal_yr = "2015" and account_nbr = a.account_nbr and fin_object_cd = a.fin_object_cd and trn_debit_crdt_cd = "D") -
(select COALESCE(sum(trn_ldgr_entr_amt),0) FROM kfsprd.kf_f_transaction_dtl where univ_fiscal_yr = "2015" and account_nbr = a.account_nbr and fin_object_cd = a.fin_object_cd and trn_debit_crdt_cd = "C")
) as "Ending Balance"
from kfsprd.kf_f_transaction_dtl a where univ_fiscal_yr = "2015" and (univ_fiscal_prd_cd between "01" and "13" or
univ_fiscal_prd_cd = "BB") and a.account_nbr between "1014000" and "1014005" and a.fin_object_cd between "0000" and "9999" and a.fin_balance_typ_cd != "CB"
group by account_nbr, fin_object_cd
order by account_nbr, fin_object_cd;
Are you able to add fin_coa_cd to the where clause? If that has the same primary key as the original table (gl_entry_t), then the first 3 columns of that table would be univ_fiscal_yr, fin_coa_cd, and account_nbr. If you have a chart code to use, it may help Oracle use that index in the main query.
I am trying to write write a nested if statement in VBA. In cobol, I would typically use the evaluate clause. But what do I use in VBA so as to avoid a long loop.
Example.
if cmbfield = "green" then
me.frame1.enable = true
else
me.frame2.enable = false
me.frame3.enable = false
end if
if cmbfield = "red" then
me.frame2.enable = true
else
me.frame1.enable = false
me.frame3.enable = false
end if
if cmbfield = "white" then
me.frame3.enable = true
else
me.frame1.enable = false
me.frame2.enable = false
end if
In the example you gave I'd use a switch command:
http://www.techonthenet.com/excel/formulas/case.php
Select Case test_expression
Case condition_1
result_1
Case condition_2
result_2
...
Case condition_n
result_n
Case Else
result_else
End Select
You could also do if ... elseif ... end if
http://www.techonthenet.com/excel/formulas/if_then.php
If condition_1 Then
result_1
ElseIf condition_2 Then
result_2
...
ElseIf condition_n Then
result_n
Else
result_else
End If
I do it this way:
Me.frame1.enabled = (cmbfield = "green")
Me.frame2.enabled = (cmbfield = "red")
Me.frame3.enabled = (cmbfield = "white")
Dim isGreen as Boolean, isRed as Boolean, isWhite as Boolean
isGreen = (cmbfield = "green")
isRed = (cmbfield = "red")
isWhite = (cmbfield = "white")
me.frame1.enabled = isGreen
me.frame2.enabled = isRed
me.frame3.enabled = isWhite
This is a shorter way to write the same code. Should work modulo syntax; hope this helps.
God damn confused at the syntax for my MYSQL query.
Is this correct... Can't find an entry in internet similar to it.
$query_game_string = '';
while($game = mysql_fetch_assoc($get_game_list)){
$query_game_string .= ' OR target = "' . $game['id'] . '" AND ancestors = "0"';
}
echo '' . $query_game_string . '';
//prints: OR target = "11" AND ancestors = "0" OR target = "12" AND ancestors = "0" OR target = "27" AND ancestors = "0" OR target = "29" AND ancestors = "0" OR target = "32" AND ancestors = "0"
$database->connect();
$comments = mysql_query(
'SELECT *
FROM ' . $database->db_prefix . 'comments
WHERE user_id = "' . $user->user_object["id"] . '"' .
$query_game_string . '
ORDER BY created DESC'
, $database->connection_handle);
$database->close();
So the actual query would be in total:
'SELECT *
FROM ' . $database->db_prefix . 'comments
WHERE user_id = "' . $user->user_object["id"] . '"' .
'OR target = "11" AND ancestors = "0" OR target = "12" AND ancestors = "0" OR target = "27" AND ancestors = "0" OR target = "29" AND ancestors = "0" OR target = "32" AND ancestors = "0"' . '
ORDER BY created DESC'
Is the syntax okay?
Don't know exactly what your are looking for but probably you need parenthesis:
OR (target = "11" AND ancestors = "0")
OR (target = "12" AND ancestors = "0")
OR (target = "27" AND ancestors = "0")
OR (target = "29" AND ancestors = "0")
OR (target = "32" AND ancestors = "0")
php to achieve that:
while($game = mysql_fetch_assoc($get_game_list))
{
$query_game_string .= ' OR (target = "' . $game['id'] . '" AND ancestors = "0")';
}
a way to simplify the query is using IN operand
OR target IN("11","12","27","29","32") AND ancestors = "0"
php:
$targets = array();
while($game = mysql_fetch_assoc($get_game_list))
{
$targets[] = '"'.$game['id'].'"';
}
$query_game_string = ' OR target IN (' . implode(",",$targets) . ') AND ancestors = "0"';