Crystal reports - How to translate a group by with condition into a report - sql

I have the following query
SELECT dbo_DIRIGEANTS.IU_DIR,
[1-CR-liste_Pixi].Siren,
[1-CR-liste_Pixi].Nic,
FROM [1-CR-liste_Pixi] LEFT JOIN dbo_DIRIGEANTS ON [1-CR-liste_Pixi].Siren = dbo_DIRIGEANTS.SIREN
GROUP BY
dbo_DIRIGEANTS.IU_DIR,
[1-CR-liste_Pixi].Siren,
[1-CR-liste_Pixi].Nic,
IIf([QUAL_JUR]>"0003","",Right([QUAL_JUR],1))
HAVING
((([1-CR-liste_Pixi].Siren) Not Like "p*")
AND (([1-CR-liste_Pixi].Nic) Not Like "p*")
AND ((dbo_DIRIGEANTS.REP_LEGAL)="1") AND (([1-CR-liste_Pixi].Nicsiège) Not Like "p*"))
ORDER BY IIf([QUAL_JUR]>"0003","",Right([QUAL_JUR],1));
What I'm interested is setting that part
GROUP BY dbo_DIRIGEANTS.IU_DIR,
[1-CR-liste_Pixi].Siren,
[1-CR-liste_Pixi].Nic,
IIf([QUAL_JUR]>"0003","",Right([QUAL_JUR],1))
And especially that part
IIf([QUAL_JUR]>"0003","",Right([QUAL_JUR],1))
Because of performance, I kept my tables and use CR's functions to deal with the condition part instead of creating a query.
I did the following:
Went to Formula selection and choose group
Chose the field I wanted
Put the formula
The error below popped out
It said my formula needs to be using boolean values.
To see if I was right, I've amended it that way IF {DIRIGEANTS.QUAL_JUR} > "0003" THEN TRUE ELSE FALSE. It worked.
TL;DR
Why I cannot do that in my expert group selection?
IF {DIRIGEANTS.QUAL_JUR} > "0003" THEN "" ELSE RIGHT({QUAL_JUR},1)
Thanks

Group selection should return Boolean but that doesn't mean you write true or false....it means you pass some thing to fields to perform job
IF {DIRIGEANTS.QUAL_JUR} > "0003"
THEN datasefield=""
ELSE database fled=RIGHT({QUAL_JUR},1)
This will do the job
Edit: Apologize as conditions are a bit confused for your requirement
Create formula and write below code
IF {DIRIGEANTS.QUAL_JUR} > "0003" THEN ""
ELSE RIGHT({DIRIGEANTS.QUAL_JUR},1)
Now go to insert group and select this formula and click ok. This will do the trick

Related

HSQL - Adding a new column in the query based on an IF condition

I need to generate a column, where in each row it checks if the Bestand is less than, equal or greater than Minbestand. If so the new column called Bestandsbewertung needs to give out Mangel, Mindestbestand or Überfluß respectively.
SELECT IF(Bestand < Minbestand, 'Mangel', IF(Bestand = MinBestand, 'Mindestbestand', 'Überstand')) AS Bestandsbewertung, Teile.*
FROM Teile
I tried this code but HSQL says it doesn't know IF.
This is what the Table looks like if it helps
It seems HSQL doesn't accept IF. After some trial and error I came to this solution to the problem.
SELECT Teile.*,
CASE Bestand WHEN < MinBestand THEN 'Mangel'
WHEN = MinBestand THEN 'Mindestbestand'
WHEN > MinBestand THEN 'Überfluß' END AS Bestandsbewertung
FROM Teile
It seems to work without any issues.

MS Access Query date range when last date not found

I have the following update query in MS Access 2013
UPDATE WXObs SET WXObs.SnowFlag = 1
WHERE (((WXObs.StationID) ="451409") And(
(WxObs.ObsDate) Between #1/3/2003# AND #3/29/2003# OR
(WxObs.ObsDate) Between #11/16/2003# AND #5/7/2004# OR
(WxObs.ObsDate) Between #10/30/2004# AND #4/30/2005#));
This works until the end date in the range is not found. For instance, if 5/7/2004 is not in the data set, then the update continues to the next end date, in this case 4/30/2005.
I would prefer it ended on the last date in the range. For instance, if the data ended on 4/21/2004, that would be last field updated between 11/16/ and 5/7/2004. The query would then continue to update again beginning on 10/30/2004.
I have tried < and <=
Thanks
You're missing some parentheses that are affecting the evaluation order, causing the behavior that you're reporting.
What you want is for each of the BETWEEN portions to be evaluated completely before the OR option is evaluated, and you need to make sure that evaluation is done by surrounding the BETWEEN expressions in parentheses to guarantee the evaluation order.
This should correct it (untested, as you've not provided the test data necessary to create a test case).
UPDATE WXObs SET WXObs.SnowFlag = 1
WHERE
(WXObs.StationID ="451409")
And
(
(WxObs.ObsDate Between #1/3/2003# AND #3/29/2003#) OR
(WxObs.ObsDate Between #11/16/2003# AND #5/7/2004#) OR
(WxObs.ObsDate Between #10/30/2004# AND #4/30/2005#)
);

Add conditions where with 2 field conditions do not run accurately

The data that appears does not match the conditions that have been applied
I implemented SQL code in the Navicat application, and have changed the structure of the code several times but it still doesn't work,
data that is not of ilart condition type
still appears
SELECT SERMAT,ILART,sum(GKSTP) as jumlah
FROM swift_zab_iw39
WHERE ILART='OVH' OR ILART='TST' and SERMAT='024147-000:09052'
GROUP BY ILART,SERMAT
Use IN operator:
WHERE ILART IN('OVH','TST') AND SERMAT = '024147-000:09052'
Add parenthesis to the OR condition in the WHERE clause as:
WHERE (ILART = 'OVH' OR ILART = 'TST') AND SERMAT = '024147-000:09052'

MS Access VBA - Query Calculations

When I run my query everything works how I need, however, upon initialising the query I receive a prompt for "Enter Parameter Value: Available". the [Required] field attempts to take the results from the [Available] Field to do some calculations. I have managed to do this through two queries but I would prefer to have it all done in one if that is possible.
SELECT tblConsumables.PartName, Sum(qryStockMovements.Quantity) AS [Available], tblConsumables.StockMax, IIf([stockmax]-[available]>0,[stockmax]-[available],0) AS Required
FROM tblConsumables INNER JOIN qryStockMovements ON tblConsumables.ID = qryStockMovements.ProductID
GROUP BY tblConsumables.PartName, tblConsumables.StockMax, IIf([stockmax]-[available]>0,[stockmax]-[available],0);
You probably need the source expression, not the alias:
SELECT tblConsumables.PartName, Sum(qryStockMovements.Quantity) AS [Available], tblConsumables.StockMax, IIf([stockmax]-Sum(qryStockMovements.Quantity) > 0,[stockmax]-Sum(qryStockMovements.Quantity), 0) AS Required

Excel MS Query - How to write parameter equals "" or show all in SQL query

Just finished writing an SQL script in the MS-Query and I'm having difficulty trying to get it to work.
What I'm after is the equivalent of this SQL where clause:
AND ((examplefield = #Para) or (#Para = ''))
So if parameter = something in the field, only show that or if the parameter = blank then show all results.
So far this is what I have which works fine if I want to select a particular item, now I just need to include the additional if blank show all.
AND (`'Project Master List$'`.`Type of Work`= ?)
This unfortunately doesn't work.
AND ((`'Project Master List$'`.`Type of Work`= ?) OR (? = ""))
Any suggestions?
Try a case?
Case When ?="" THEN
'docode'
WHEN ?="OtherValue" THEN
'DoCode'
Else
'DoCode '
End
The IIF Example:
iif(?="",
iif(?="OtherValue",ReturnSomethingTrue,ReturnSomethingFalse)
,ReturnSomethingTrue,ReturnsomethingFalse)
I looked back at my original question and realised I wrapped the where clause in the wrong quotes. See below
Wrong statement
AND ((`'Project Master List$'`.`Type of Work`= ?) OR (? = ""))
Correct statement
AND (`'Project Master List$'`.`Type of Work`= ? OR ? = '')
Once I'd made the change right at the end of the clause it worked.