Crystal Reports v14 not finding all null values - sql

Alright, I've run into this before and have gotten everything to work correctly in the past. I have an SQL code that was created that now needs to be turned into a crystal report. The SQL shows 956 lines, but Crystal is only showing 886.
Here is the SQL code:
SELECT
I4240,
I4201,
I4202,
I4203,
I4204,
I4206,
I4213,
I4214,
I4225,
I4208,
I4299
FROM
MT.INVENTORY
WHERE
(
I4202 IN ('UNKNONWN','VERIFY MFR','OTHER','VARIOUS','TBD','NA','N/A') OR
(
I4203 IN ('UNKNONWN','VERIFY MODEL NUMBER','OTHER','VARIOUS','TBD','NA','N/A','MISCELLANEOUS')
OR I4203 IS NULL
OR LENGTH(I4203)=0
) OR
(
I4204 IN ('UNKNOWN DESCRIPTION','VERIFY DESCRIPTION','OTHER','VARIOUS','TBD','NONE - NO STD USED','NA','N/A','MISCELLANEOUS')
OR I4204 IS NULL
OR LENGTH(I4204)=0
)
) AND
I4240 NOT IN ('MT','STD','NESD')
ORDER BY I4240,I4202,I4203,I4204
and the record selection formula from CR:
(
{Inventory.I4240} <> 'mt' and
{Inventory.I4240} <> 'std' and
{Inventory.I4240} <> 'nesd'
)
AND
(
(
{Inventory.I4202} = 'UNKNONWN' OR
{Inventory.I4202} = 'VERIFY MFR' OR
{Inventory.I4202} = 'OTHER' OR
{Inventory.I4202} = 'VARIOUS' OR
{Inventory.I4202} = 'TBD' OR
{Inventory.I4202} = 'NA' OR
{Inventory.I4202} = 'N/A'
)
OR
(
{Inventory.I4203} = 'UNKNONWN' OR
{Inventory.I4203} = 'VERIFY MODEL NUMBER' OR
{Inventory.I4203} = 'OTHER' OR
{Inventory.I4203} = 'VARIOUS' OR
{Inventory.I4203} = 'TBD' OR
{Inventory.I4203} = 'NA' OR
{Inventory.I4203} = 'N/A' OR
{Inventory.I4203} = 'MISCELLANEOUS' OR
ISNULL({Inventory.I4203}) OR
LENGTH(trim({Inventory.I4203})) < 1 OR
INSTR(trim({Inventory.I4203}), "") = 0 OR
TRIM({Inventory.I4203}) = ""
)
OR
(
{Inventory.I4204} = 'UNKNOWN DESCRIPTION' OR
{Inventory.I4204} = 'VERIFY DESCRIPTION' OR
{Inventory.I4204} = 'OTHER' OR
{Inventory.I4204} = 'VARIOUS' OR
{Inventory.I4204} = 'TBD' OR
{Inventory.I4204} = 'NONE - NO STD USED' OR
{Inventory.I4204} = 'NA' OR
{Inventory.I4204} = 'N/A' OR
{Inventory.I4204} = 'MISCELLANEOUS' OR
ISNULL({Inventory.I4204}) OR
LENGTH(trim({Inventory.I4204})) < 1 OR
INSTR({Inventory.I4204}, "") = 0 OR
TRIM({Inventory.I4204}) = ""
)
)
Any help would be appreciated.

In Crystal, if a particular field can be null then you need to check for that condition as the very first thing you do with it, otherwise the entire formula will error out and nothing will be evaluated.
So in your case, fields I4203 and I4204 need the isnull() check moved to the top of their respective sections at the very least. If I4240 and I4202 can be null, then you should handle those conditions as well.
Also, you have a couple references to the word "UNKNONWN"; is that a typo?

The issue was that the report options were set to use null as default, but for some reason in the record selection formula it was set to exception. Once that was set to the default setting it worked without any issues and the counts were correct.

Related

Using a CASE WHEN with multiple Whens that is only resulting in a BOOLEAN value

I am working on writing a SQL Query which is using a CASE line with multiple When's, and I was wondering why my result is only showing BOOLEAN (True/False) Values. Ideally I would like it to show whatever is after the THEN's in my code.
--with loan as (
SELECT DISTINCT
rtw.identifierdimsk
,lmmf.milestonesk
,lmd.groupname
,rtw.typecode
,rtw.campaignname
,rtw.partnername
,rtw.sourcename
,lmmf.date
,rtw.typecode = CASE WHEN rtw.typecode = 'PROS' THEN 'Prospect'
WHEN rtw.typecode = 'CARI' THEN 'Deluxe'
WHEN rtw.typecode = ('CARIC') OR rtw.typecode = ('CTE') THEN 'CSignal'
WHEN rtw.typecode = 'RMT' THEN 'Pre Pull'
WHEN rtw.typecode in ('90','90PLUS','C90','C90PLUS','BP','ELO','AUTO','POP') THEN 'In-process'
WHEN rtw.typecode = 'XU3%' THEN 'U3'
WHEN rtw.typecode = '%CT%' THEN 'Misc'
END AS Value
FROM rtal_winner rtw
INNER JOIN one_fact lmmf ON lmmf.identifierdimsk = rtw.identifierdimsk
INNER JOIN one_dim lmd ON lmd.milestonesk = lmmf.milestonesk
AND lmmf.date >= '2022-10-25'
Because you are comparing rtw.typecode to the result of the case expression:
rtw.typecode = CASE ...
remove the comparison part:
, lmmf.date
, CASE
WHEN rtw.typecode = 'PROS' THEN 'Prospect'
-- ...
END AS Value
FROM rtal_winner rtw

case when using multiple conditions across multiple columns

So quick example:
I need to change that 'imperial' to 'Metric' in the UnitsofMeterRemoved Column. However it has to be when meter model = g4 and MeterManufacturerRemoved = KROMSCHRODER.
I have tried this
SELECT *,
CASE WHEN MeterModelRemoved = 'G4'
AND MeterManufacturerRemoved = 'KROMSCHRODER'
AND UnitsofMeterRemoved = 'Imperial'
THEN UnitsofMeterRemoved = 'Metric'
END AS MeterModelRemoved
FROM CTE_2
But the Imperial is still showing up? Any ideas why this may be happening?
use below
SELECT * EXCEPT(UnitsofMeterRemoved),
CASE WHEN MeterModelRemoved = 'G4'
AND MeterManufacturerRemoved = 'KROMSCHRODER'
AND UnitsofMeterRemoved = 'Imperial'
THEN 'Metric'
ELSE UnitsofMeterRemoved
END AS UnitsofMeterRemoved
FROM CTE_2

Visual Fox Pro Word Automation

LOCAL oWord, oDocument, oRange, Lc_start, Lc_expr, Lc_ris, Ln_count, Lc_val
DIMENSION Lc_funct[1]
Lc_expr = ""
Ln_count = 1
oWord = CREATEOBJECT("Word.Application")
oWord.Visible = .T.
cFile = GETFILE()
oDoc = oWord.Documents.Add(m.cFile)
oRange = oWord.ActiveDocument.Range()
nWordCount = oRange.Words.Count
oRange.Collapse(1)
FOR nWord = 1 TO m.nWordCount-1
oRange.Expand(2)
cWord = oRange.Text
DO CASE
CASE m.cWord = "<|<"
Lc_start = .T.
Lc_Expr = ""
CASE m.cWord = ">|>"
Lc_start = .F.
Lc_funct[Ln_count] = Lc_Expr
Ln_count = Ln_count + 1
DIMENSION Lc_funct[Ln_count]
CASE m.Lc_start
Lc_expr = Lc_expr + m.cWord
OTHERWISE
*don't do anything
ENDCASE
oRange.Collapse(0)
ENDFOR
FOR i = 1 TO Ln_count-1
oRange = oWord.ActiveDocument.Range()
oRange.Find.Text = Lc_funct[i]
oRange.Find.Replacement.Text = EVALUATE(Lc_funct[i])
lFound = oRange.Find.Execute( , , , , , , , , , , 2 )
ENDFOR
FOR i = 1 TO Ln_count-1
oRange = oWord.ActiveDocument.Range()
oRange.Find.Text = "<|<"
oRange.Find.Replacement.Text = ""
lFound = oRange.Find.Execute( , , , , , , , , , , 2 )
ENDFOR
FOR i = 1 TO Ln_count-1
oRange = oWord.ActiveDocument.Range()
oRange.Find.Text = ">|>"
oRange.Find.Replacement.Text = ""
lFound = oRange.Find.Execute( , , , , , , , , , , 2 )
ENDFOR
MESSAGEBOX("DONE")
Hello everyone. I wrote this code to automate Word from Visual Fox Pro. I put between the escapes "<|<" and ">|>" some VFP code(like take some values from tables and so on). At the press of a button, the code scans all the document and, when find these escapes, evaluates the istructions between. The last two FORs eliminate the escape strings.
The code works, but I ask. There is a better way to do what I look for?
Also, if I have a table, there is a way to decide BEFORE the automation which columns I want to pass inside the Word document?

How to add a column in a sql query with selection of the result

I have a sql statment like this:
SELECT a.link_id, a.Speed_Limit_1, a.Speed_Limit_2, a.speed_limit_source, g.autos, g.trucks, g.motorcycles, 'vehicleType' as vehicleType
FROM g, f, d, a
WHERE f.access_id = g.access_id
AND d.condition_id = f.condition_id
AND g.access_id = a.access_id
result:
link_id......autos...trucks...motorcycles.........vehicleTypes
1..........|.......Y....|....Y......|.....N.................|.............?
2..........|.......Y....|....Y......|.....Y.................|.............?
3..........|.......Y....|....Y......|.....N.................|.............?
4..........|.......Y....|....N......|.....Y.................|.............?
I will add the column "vehicleTypes. Inside this column should be:
0 if autos, trucks and motorcycles are allowed (e.g. row 2)
1 if only cars are allowed
2 if only trucks are allowed
3 if only motorcycles are allowed
How can I do this?
This should do it.
I added an ELSE -1 to indicate where it didnt match any of the criteria.
SELECT
a.link_id,
a.Speed_Limit_1,
a.Speed_Limit_2,
a.speed_limit_source,
g.autos, g.trucks,
g.motorcycles,
CASE
WHEN g.autos = 'Y' AND g.trucks = 'Y' AND g.motorcycles = 'Y' THEN 0
WHEN g.autos = 'Y' AND g.trucks = 'N' AND g.motorcycles = 'N' THEN 1
WHEN g.autos = 'N' AND g.trucks = 'Y' AND g.motorcycles = 'N' THEN 2
WHEN g.autos = 'N' AND g.trucks = 'N' AND g.motorcycles = 'Y' THEN 3
ELSE -1
END as vehicleTypes
FROM g, f, d, a
WHERE f.access_id = g.access_id
AND d.condition_id = f.condition_id
AND g.access_id = a.access_id
You should use CASE WHEN block
for example in Oracle:
https://www.techonthenet.com/oracle/functions/case.php

IF ELSE CONDITION IN SQL WHERE CLAUSE

MY QUERY IS
DECLARE #AutoApprove BIT
SET #AutoApprove = (
SELECT AutoApprove
FROM dbo.CommentBox_Setting
WHERE UserModuleID = #myModuleID
AND PortalID = #portalID
AND CultureCode = #cultureCode
)
From this i will get whether 1 OR 0 (TRUE OR FALSE) furthermore i have
SELECT * FROM ComentBox_Comment
WHERE UpperModuleID = #UpperModuleID
AND ModuleID = #myModuleID
AND portalID = #portalID
AND cultureCode = #cultureCode
AND //Here i need to check condition
(IF(#AutoApprove=0){ THEN isapprove=1}else {do not check})
Note here isapprove is table filedName
I know ,i can do this with long query i need short and easy way.
Help me out.
Try something like
AND CASE WHEN #AutoApprove=0 THEN isapprove ELSE 1 END = 1
This will check isapprove = 1 if #AutoApprove = 0, or 1=1(ignore) otherwise.
CASE (Transact-SQL)