I have a formula field (#stock) in my Crystal report, I want to put in this formula field
Initial value = {Stock.ActualStock}
{Stock.ActualStock} when {Delivry.Quantity} is null.
(#stock) - {Delivry.Quantity} when {Delivry.Quantity} is not null
This is the code i tried:
if IsNull({Delivry.Quantity}) Then
formula = {Stock.ActualStock}
Else
formula = formula - {Delivry.Quantity}
End If
But i get the vlue of {Delivry.Quantity} in (#stock) when {Delivry.Quantity}
it is not null, and when it is null i get this error message:
Ce nom de champs est inconnu.
Erreur dans la formule de stock:
if IsNull({Delivry.Quantity}) Then
So how can i get the values i want in this formula field??
Thanks in advance.
Related
I'm using T-SQL language and I'm wondering the best way to get specific information from a string.
Example of string :
Category : azd Nom du fichier : 684157 Type de doc : info Id : 21542
The idea is to get the value "684157", which will be always between "fichier :" and "Type".
I have tried with substring and charindex but I miss something.
Here is my code
select substring(com, charindex('fichier : ', com)+len('fichier : '), charindex('Type', com)-charindex('fichier : ', com) + len('Type'))
from myTable
There might be a neater way of doing this but here's a method using CHARINDEX and SUBSTRING.
SELECT SUBSTRING(com,
CHARINDEX('fichier :', com) + LEN('fichier :'), -- start index
CHARINDEX('Type :', com) - (CHARINDEX('fichier :', com) + LEN('fichier :'))) -- length
FROM MyTable
The startIndex is the index of fichier : plus the length of fichier :. The end index is the index of Type :. For SUBSTRING we need to use the start index and the length. To calculate the length of the substring we use the index of Type : and subtract what we calculated for startIndex.
This is what I would do:
SELECT LEFT(S.CutString,CHARINDEX(' Type :',S.CutString)) AS FinalString
FROM (VALUES('Category : azd Nom du fichier : 684157 Type : info Id : 21542'))V(String) --Would be your table
CROSS APPLY (VALUES(STUFF(V.String,1,CHARINDEX('fichier : ',V.String) + LEN('fichier : '),'')))S(CutString);
additional variant:
SELECT parsename(replace(replace(com,'fichier : ','.'), 'Type','.'),2)
FROM MyTable
test:
I am working on a recurcive query and I work on a guid stocked in a varchar(90) column. But I got an cast type exception from pgAdmin when working with Postgres 11.1
I'm stuck and I don't know what could i do to solve this, if any one can help me.
https://docs.postgresql.fr/8.4/queries-with.html
Postgres CTE : type character varying(255)[] in non-recursive term but type character varying[] overall
with recursive sousSujet(typerefin,coderefin,typerefout,coderefout,type,profondeur,chemin, boucle) as (
SELECT p.typerefin, p.coderefin, p.typerefout , p.coderefout , p.type,1, ARRAY[p.coderefout]::varchar(90)[] ,false
FROM relation p
WHERE p.coderefin='2019094070' and p.typerefin='PROJET'
--union all
union
SELECT p.typerefin, p.coderefin, pr.typerefout, pr.coderefout, p.type ,pr.profondeur+1,
--chemin || pr.coderefout,pr.coderefout = ANY(pr.chemin)
chemin::varchar(90)[] || pr.coderefout,pr.coderefout = ANY(pr.chemin::varchar(90)[])
FROM relation p,sousSujet pr
-- WHERE p.coderefin = pr.coderefout
WHERE p.coderefin = pr.coderefout AND NOT pr.boucle and pr.profondeur < 10
)
SELECT typerefin,coderefin,typerefout,coderefout,type,profondeur
FROM sousSujet
order by coderefout limit 20
ERROR: ERREUR: dans la requête récursive « soussujet », la colonne 7 a le type character varying(90)[] dans le terme non
récursif mais le type global character varying[]
LINE 3: ...oderefin, p.typerefout , p.coderefout , p.type,1, ARRAY[p.co...
^
HINT: Convertit la sortie du terme non récursif dans le bon type.
The easiest is to cast everything to text, by using ARRAY[p.coderefout::text] in the anchor query and chemin::text || pr.coderefout in the recursive query. There is no need to cast everything to an array
with recursive sousSujet(typerefin,coderefin,typerefout,coderefout,type,profondeur,chemin, boucle) as (
SELECT p.typerefin, p.coderefin, p.typerefout, p.coderefout, p.type, 1,
ARRAY[p.coderefout::text], false
FROM relation p
WHERE p.coderefin='2019094070' and p.typerefin='PROJET'
union all
SELECT p.typerefin, p.coderefin, pr.typerefout, pr.coderefout, p.type ,pr.profondeur+1,
chemin::text|| pr.coderefout,
pr.coderefout = ANY(pr.chemin)
FROM relation p
join sousSujet pr
on p.coderefin = pr.coderefout
AND NOT pr.boucle
and pr.profondeur < 10
)
SELECT typerefin,coderefin,typerefout,coderefout,type,profondeur
FROM sousSujet
order by coderefout limit 20
The error complains that the term
ARRAY[p.coderefout]::varchar(90)[]
in the non-recursive part has type varchar(90)[], but the corresponding expression
chemin::varchar(90)[] || pr.coderefout
in the recursive part has type varchar[].
This is because the array concatenation operator || removes the type modifier:
SELECT '{a,b,c}'::varchar(90)[] || 'd'::varchar(90) \gdesc
Column | Type
----------+---------------------
?column? | character varying[]
(1 row)
You's have to add an explicit cast to the result of the concatenation:
(chemin || pr.coderefout)::varchar(90)[]
To avoid annoyances like that, don't use type modifiers there. I'd just use varchar or shorter, but synonymous, text. You are not using the column in the final result anyway.
Hello I am working in crystal and am wanting to add a formula field called Group 1, and want to use SQL query like this:
CASE '{?Group 1}'
WHEN 'Location' THEN (CASE WHEN COALESCE(TABLE_NAME_1.COLUMN_NAME_1, TABLE_NAME_1.COLUMN_NAME_2) IS NULL THEN '*Unspecified Location'
WHEN TABLE_NAME_2.COLUMN_NAME_1 IS NULL THEN CONCAT('*Unknown Location', CONCAT(' [',CONCAT(COALESCE(TABLE_NAME_1.COLUMN_NAME_1, TABLE_NAME_1.COLUMN_NAME_2),']')))
WHEN TABLE_NAME_2.COLUMN_NAME_2 IS NULL THEN CONCAT('*Unnamed Location', CONCAT(' [',CONCAT(TABLE_NAME_2.COLUMN_NAME_1,']')))
ELSE TABLE_NAME_2.COLUMN_NAME_2 END)
ELSE NULL END GROUP_1
Not entirely sure how this translates into crystal. Any help would be great.
Thank you
Ok I reworked the formula and came up with:
IF {?Group1} = "Location" THEN
IF ISNULL({TABLE_NAME_1.COLUMN_NAME_1}) THEN "*Unspecified Location" ELSE
IF ISNULL({TABLE_NAME_1.COLUMN_NAME_2}) THEN "*Unspecified Location" ELSE
IF ISNULL({TABLE_NAME_2.COLUMN_NAME_1}) THEN "*Unknown Location" ELSE
IF ISNULL({TABLE_NAME_2.COLUMN_NAME_2}) THEN "*Unnamed Location"
ELSE {TABLE_NAME_2.COLUMN_NAME_2}
I think this might work. Would you agree or is there a better way?
your conversion is almost correct need some changes check below.
IF {?Group1} = "Location" THEN
(
IF (ISNULL({TABLE_NAME_1.COLUMN_NAME_1}) or ISNULL({TABLE_NAME_1.COLUMN_NAME_2}))
THEN "*Unspecified Location"
ELSE IF ISNULL({TABLE_NAME_2.COLUMN_NAME_1})
THEN "*Unknown Location " &IIF((ISNULL({TABLE_NAME_1.COLUMN_NAME_1}) or ISNULL({TABLE_NAME_1.COLUMN_NAME_2})),{TABLE_NAME_1.COLUMN_NAME_1},{TABLE_NAME_1.COLUMN_NAME_2})
ELSE IF ISNULL({TABLE_NAME_2.COLUMN_NAME_2})
THEN "*Unnamed Location " & {TABLE_NAME_2.COLUMN_NAME_1}
)
ELSE {TABLE_NAME_2.COLUMN_NAME_2}
i have a report I am trying to modify in Crystal. It has a data field that has a formula in it, but I want to use another formula.
how to convert above crystal synax to basic syntax in crystal report
IIF ({rpl_bal_bundlelabels.recordcode} = "2",0 ,
IIF ({rpl_bal_bundlelabels.StdOdd} = "OS",
IIF ({rpl_bal_bundlelabels.totalsupply} > {rpl_bal_bundlelabels.standard},
IIF (({rpl_bal_bundlelabels.totalsupply} mod {rpl_bal_bundlelabels.standard}) > 0,
{rpl_bal_bundlelabels.totalsupply} - (({rpl_bal_bundlelabels.totalsupply} \
{rpl_bal_bundlelabels.standard}) * {rpl_bal_bundlelabels.standard}) ,
{rpl_bal_bundlelabels.standard} ) ,{rpl_bal_bundlelabels.totalsupply} ) ,
{rpl_bal_bundlelabels.BundleCopies} ) )
create a new formula
paste the text
correct the syntax, if necessary
set the result to formula =
I have column its name 'owner' and its has the following vlaue
ownerName
--------
Koni
Sally
Jimmi
Jone
Sami
and i want to print this value in crystal report as following using formula
ownerName
Koni
--Sally
----Jimmi
------Jone
--------Sami
thank you for any help
This can be done by using the following formula criteria:
If (RecordNumber > 1) Then
ReplicateString("-", RecordNumber) + {DatabaseFieldName}
Else
{DatabaseFieldName}