Getting Error in Queries in COGNOS 10.2 - cognos-10

I am new to Development in COGNOS 10.2. I am trying to create a logic:
IF(ParamCount('ord')=1) THEN ('SI')ELSE('NULL')
IF(ParamCount('ord')>1) THEN ('MI')ELSE('NULL')
IF(ParamCount('ord')< ) THEN('NULL')
The first one give no error how ever the last two gives error. Please suggest.
Niha

Use search case. Following is how it should be. Also if you are trying to return null, it should not be in quotes.
CASE
WHEN ParamCount('ord') = 1 THEN 'SI'
WHEN ParamCount('ord') > 1 THEN 'MI'
WHEN ParamCount('ord') < 1 THEN null
ELSE null
END

Related

Does a OUTER-JOIN always divide the query in two parts, leaving the part on the right empty if not complete in Progress?

I'm trying to do an OUTER-JOIN in progress using this page as inspiration. My code is as follows
OPEN QUERY qMovto
FOR EACH movto-estoq
WHERE movto-estoq.lote BEGINS pc-lote
AND movto-estoq.it-codigo BEGINS pc-it-codigo
AND movto-estoq.dt-trans >= pd-data1
AND movto-estoq.dt-trans <= pd-data2
AND movto-estoq.cod-emitente = pi-cod-emitente,
EACH item OUTER-JOIN
WHERE movto-estoq.it-codigo = item.it-codigo,
EACH item-cli OUTER-JOIN
WHERE item-cli.item-do-cli BEGINS pc-item-cli
AND movto-estoq.cod-emitente = item-cli.cod-emitente
AND movto-estoq.it-codigo = item-cli.it-codigo
AND movto-estoq.un = item-cli.unid-med-cli,
EACH nota-fiscal OUTER-JOIN
WHERE movto-estoq.nro-docto = nota-fiscal.nr-nota-fis
BY movto-estoq.dt-trans DESCENDING BY movto-estoq.hr-trans DESCENDING.
The problem that is happening is when 1 element in null, all the other elements that are in the OUTER-JOIN are appearing as null as well, even though they are not null. Is there a better way to write this code? Should I put 'LEFT' before the OUTER-JOIN? Thanks for your time.
To make your example easier, consider making it work from ABL dojo. The following code:
define temp-table ttone
field ii as int
.
define temp-table tttwo
field ii as int
field cc as char
.
create ttone. ttone.ii = 1.
create ttone. ttone.ii = 2.
create tttwo. tttwo.ii = 2. tttwo.cc = "inner".
create tttwo. tttwo.ii = 3. tttwo.cc = "orphan".
define query q for ttone, tttwo.
open query q
for each ttone,
each tttwo outer-join where tttwo.ii = ttone.ii.
get first q.
do while available ttone:
message ttone.ii tttwo.cc.
get next q.
end.
Can be run from https://abldojo.services.progress.com/?shareId=600f40919585066c219797ed
As you can see, this results in :
1 ?
2 inner
The join which is not available is shown as unknown. The value of the outer part of the join is shown.
Since you do not show how you are getting an unknown value for everything, maybe you are concatenating the unknown values?

Need to Print Value of a Variable using Paste in R

I am trying to create a data frame of various error messages based on Data to be cross checked between two dataframes and storing the message in a vector in an iterative manner . I am using the following snippet for this purpose :
> for(j in 1:nrow(MySQL_Data)){ date_mysql=
> paste("MySQL_Data[",j,",1]") date_red= paste("RED_Data[",j,",1]")
> body= c() if(!date_mysql == date_red) {
> body<- append(body,paste("'There is data missing for date",date_mysql,"in",table2)) }else {
> NULL }}
My table2 variable prints as MYSQL_Data[2,1] instead of the actual value of the variable which is a date
Following is the Output :
"'There is data missing for date MySQL_Data[ 2 ,1] in Dream11_UserRegistration"
Can someone help me with the error that I am committing here..
Thanks in Advance !
Your use of paste in the definitions of data_mysql and data_red makes no sense. I’m assuming that what you actually want is this:
data_mysql = MySQL_Data[j, 1]
data_red = RED_Data[j, i]
Furthermore, you’re resetting body in every loop iteration so it will only ever hold a single element.

How to use AND in a CASE sqlite statement for validation check?

I'v a SQLite database and I want to generate a kind of validation check.
The main target is to compare three fields in a table. If stnd_sht has the value 'nicht gegeben' then there should be a entry either in mass_sof of in mass_6m, if not then plausibility is not given.
So far I tried the following:
SELECT
b.baum_id AS baum_id,
CASE
WHEN b.stnd_sht ='nicht gegeben' AND b.mass_sof IS NULL THEN 'fehler'
WHEN b.stnd_sht ='nicht gegeben' AND b.mass_6m IS NULL THEN 'fehler'
ELSE 'plausibel' END AS plaus
FROM baeume b;
and...
SELECT
b.baum_id AS baum_id,
CASE WHEN (b.mass_sof IS NULL OR b.mass_6m IS NULL) AND b.stnd_sht ='nicht gegeben' THEN 'fehler'
ELSE 'plausibel' END AS plaus
FROM baeume b;
Everything works fine without any AND or OR operator but as I add additional expressions the result is not correct.
Is the AND operator not supportet by the CASE statement, or am I totaly wrong and the statement needs another structure or has to be more complex?
Thanks in advance, Patrick
These expressions are syntactically correct, but do not correspond to the explanation.
Sometimes, it helps to reverse a logical condition.
According to the explanation, there is an error if stnd_sht is nicht gegeben and if both the mass_sof and mass_6m values are NULL.
This would correspond to the following expression:
SELECT baum_id,
CASE WHEN stnd_sht = 'nicht gegeben' AND
mass_sof IS NULL AND
mass_6m IS NULL
THEN 'fehler'
ELSE 'plausibel'
END AS plaus
FROM baeume;
This could be simplified a little:
SELECT baum_id,
CASE WHEN stnd_sht = 'nicht gegeben' AND
COALESCE(mass_sof, mass_6m) IS NULL
THEN 'fehler'
ELSE 'plausibel'
END AS plaus
FROM baeume;

DateTime parsing in PowerShell

I'm trying to write a PowerShell script that will generate a table of information with two columns: a name, and a date (which will be retrieved from a third-party application - in this case svn.exe).
The overall script works well, but I'm struggling to get the date that the server sends back into the DataTable. Here's a simplified version of my script:
# Set up a DataTable and initialise columns
$table = New-Object system.Data.DataTable “Test Table”
$col1 = New-Object system.Data.DataColumn Name,([string])
$col2 = New-Object system.Data.DataColumn DateFromServer,([DateTime])
$table.columns.add($col1)
$table.columns.add($col2)
# Create a new row and add the data
$row = $table.NewRow()
$row.Name = "Test"
$lastCommit = GetDateFromExternalApp
$lastCommit.GetType() # this returns DateTime as I would expect
$row.DateFromServer = $lastCommit # this throws up an error
$table.Rows.Add($row)
# Output the table
$table | Format-Table -AutoSize
# This function simulates what the actual function does
# (the real one goes to SVN and pulls down data, but it
# ends up with the same resulting date)
Function GetDateFromExternalApp
{
$externalAppDate = "2012-09-17T16:33:57.177516Z"
return [DateTime]($externalAppDate)
}
The problem (noted in comments in the script above) is that while the function seems to be happily returning a DateTime instance, when I try to add this into the table row's DateFromServer column it's throwing up an error:
Exception setting "DateFromServer": "Unable to cast object of type 'System.Management.Automation.PSObject' to type 'System.IConvertible'.Couldn't store <18/09/2012 2:33:57 AM> in DateFromServer Column. Expected type is DateTime." At line:13 char:6
+ $row. <<<< DateFromServer = $lastCommit
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
However, the call to $lastCommit.GetType() shows that this is indeed a DateTime - and in fact if I add this line somewhere in the script:
$lastCommit
then I can see a nicely formatted datetime, suggesting that it is indeed parsing it and converting it correctly:
Date : 18/09/2012 12:00:00 AM
Day : 18
DayOfWeek : Tuesday
DayOfYear : 262
Hour : 2
Kind : Local
Millisecond : 177
Minute : 33
Month : 9
Second : 57
Ticks : 634835324371775160
TimeOfDay : 02:33:57.1775160
Year : 2012
DateTime : Tuesday, 18 September 2012 2:33:57 AM
As such I'm quite puzzled as to why I'm getting the exception above. I realise that PowerShell does function return values differently than C#, but it looks to me like the function is returning the right type!
The issue here is due to a bug in PowerShell's type adaptation system (I would recommend reporting this to Microsoft if you have not already done so).
When you work with objects in PowerShell, you are actually working with a PSObject wrapper. Most calls (like GetType) are forwarded to the underlying object, though you can add additional members that do not interact with the object itself:
PS> Get-Date | Add-Member NoteProperty Yowza 'for example' -PassThru | Format-List y*
Yowza : for example
Year : 2012
Normally this is not an issue, as PowerShell has extensive type coercion capabilities. In the case of DataRow however, there appears to be a bug with the DataRowAdapter type used to support the property access syntax. If you use the indexer directly, $row['DateFromServer'] = $lastCommit instead of $row.DateFromServer, the value is correctly unwrapped before it is sent to the .NET type.
You can also get around this by unwrapping the value yourself, either using a cast (as vonPryz already showed: [DateTime]$lastCommit), or by retrieving the BaseObject ($lastCommit.PSObject.BaseObject).
I'd like to know the reason for this behaviour too.
Anyway, you can work around the problem by casting the date variable as DateTime or by explicitly declaring it to be one. Like so,
...
$row.DateFromServer = [DateTime]$lastCommit # Doesn't throw exception
...
Or
...
[DateTime]$lastCommit = GetDateFromExternalApp
$row.DateFromServer = $lastCommit # Doesn't throw exception
...
I suspect the reason is as stated in the error message:
"Unable to cast object of type 'System.Management.Automation.PSObject' to type 'System.IConvertible'...Expected type is DateTime." At line:13 char:6
What that is saying is that PowerShell tried to convert $lastCommit into a date and time but failed. The best way is, as vonPryz suggests - cast it to [datetime]
To see the issue more clearly, try looking at the both:
$lastcommit.gettype() and
$row.DateFromServer.gettype()
I don't have the GetDateFromExternalApp to check

I am getting Object reference Not set to an instance of an object error in my asp.net mvc aplication

I have this code there Federal_Mandate I am checking weather this MandateType is 1 or 0
if its one I am just converting this as 1 or 0
mandate.Federal_Mandate = collection["MandateType"].ToString().Equals("Federal") ? Convert.ToByte(1) : Convert.ToByte(0);
and my datbase Federal_mandate datatype has tiinyint.
is that something doing wrong i am here.. why I am gettting object reference error here?
thanks
one of mandate, collection and collection["MandateType"] is null. Set a breakpoint and find out which.
It's pretty hard to figure it out but ... couldn't it be cause your collection["MandateType"] is null?
Maybe you can change it to something like this:
mandate.Federal_Mandate = (collection["MandateType"] ?? "").ToString().Equals("Federal") ? Convert.ToByte(1) : Convert.ToByte(0);
You need to check your collection to see if its null before calling a method on it:
mandate.Federal_Mandate = Convert.ToByte(0);
if(collection["MandateType"] != null)
{
mandate.Federal_Mandate = collection["MandateType"].ToString().Equals("Federal") ? Convert.ToByte(1) : Convert.ToByte(0);
}

Resources