I have a calculated column to check if "Last Payment" is less than 90 days from "withdrawaldate". Expression:
IIf(DateDiff('d',[Last Payment],[withdrawaldate])<=90,'1')
If I edit this in sql view it works perfectly. However if i edit this using query builder it breaks and says "Invalid syntax" highlighting '1' as the invalid section.
"Last Payment" is also a calculated field if that makes any difference?
What am I missing??
Please help
Thanks in advance!
Edit
SQL view as Follows:
SELECT
Book.Cause_Date,
Book.Is_Archived,
Book.Status, Book.Handover_Status,
Max(Payments.[Capture Date]) AS [Last Payment],
Withdrawaltest.ACCOUNTNO,
Withdrawaltest.WITHDRAWALDATE,
Withdrawaltest.WITHDRAWALREASON,
IIf(Abs(DateDiff('d',[Last Payment], [WITHDRAWALDATE])<=90)='1',"Yes","No") AS [Paid in 90Days],
IIf((Abs(DateDiff('m',[Cause_Date],[WITHDRAWALDATE])<=14)='1' And [Handover_Status]='3') Or (Abs(DateDiff('m',[Cause_Date], [WITHDRAWALDATE])<=9)='1' And [Handover_Status]='1'),'No','Yes') AS [Out Of Term],
IIf([Paid in 90Days]="Yes" Or [Out Of Term]="No","KEEP","DontBother") AS [Keep?]
FROM
Payments RIGHT JOIN (Book INNER JOIN Withdrawaltest ON Book.Case_Reference = Withdrawaltest.ACCOUNTNO) ON Payments.[Case Reference] = Withdrawaltest.ACCOUNTNO
GROUP BY
Book.Cause_Date, Book.Is_Archived,
Book.Status, Book.Handover_Status, Withdrawaltest.ACCOUNTNO,
Withdrawaltest.WITHDRAWALDATE, Withdrawaltest.WITHDRAWALREASON,
IIf((Abs(DateDiff('m',[Cause_Date],[WITHDRAWALDATE])<=14)='1' And [Handover_Status]='3') Or (Abs(DateDiff('m',[Cause_Date],
[WITHDRAWALDATE])<=9)='1' And [Handover_Status]='1'),'No','Yes')
ORDER BY
Max(Payments.[Capture Date]) DESC;
First, your expression is missing the "False" part of the IIf:
IIf(DateDiff('d',[Last Payment],[withdrawaldate])<=90, '1', <FALSE-PART>)
Second, if you use German Access, then you must use ; instead of , for functions in Query design view.
IIf(DateDiff('d';[Last Payment];[withdrawaldate])<=90; '1'; <FALSE-PART>)
But in SQL view (that's "international") it is ,.
Related
Helo. Today is my another fight day with OLAP raport with optional parameter. I have problem with MDX query. I wrote it like this:
select
NON EMPTY {{[Measures].[VALUE]}} ON COLUMNS,
NON EMPTY {
IIF(ISEMPTY([CUSTOMER].[${param}]) //CHECKING IF PARAMETER IS EMPTY
,{[CUSTOMER].[COUNTRY].Members},
{[CUSTOMER].[${param}]}
)
}ON ROWS
from [TRANSACTIONS]
${param} is my optional parameter for [CUSTOMER].[COUNTRY]. I unchecked "required" check button for my parameter, so OLAP should have all [VALUE] after executing it without parameter. And there is a problem, because after launching my OLAP raport parameter probably wants to be filled with something. It gives me an error.
Profile attribute 'param' not existing.
But I dont want to fill it with profile attribute. I have created list of values, and analytical driver for my parameter, which I use to pass possible values to my list box string parameter - ${param}.
Is there possibility to have OLAP report with optional parameter? Any BI master here?
I would be greatfull for any help.
Update: I have done something like this, I think this syntax is right, (I was checking SpagoBI examples)
WITH MEMBER [CUSTOMER].[SELECTED] AS ' Parameter("param") ' , SOLVE_ORDER = 2
MEMBER [CUSTOMER].[LEN] AS ' LEN(Parameter("param")) ', SOLVE_ORDER = 1
select
NON EMPTY {{[Measures].[VALUE]}} ON COLUMNS,
NON EMPTY {
IIF([CUSTOMER].[LEN]=0
,{[CUSTOMER].[COUNTRY].Members},
{[CUSTOMER].[CUSTOMER].[SELECTED]}
)
}ON ROWS
from [TRANSACTIONS]
But now I have same error for both possibilities (set/unset) parameter
javax.servlet.jsp.JspException: org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: com.tonbeller.jpivot.olap.model.OlapException: 1
Any ideas? Thanks :)
This question is a direct copy oF your previous posts:
https://stackoverflow.com/questions/38970610/olap-report-with-optional-parameter
Is ${param} is a string?
If it is a string then the following should function:
WITH MEMBER [Measures].[x] AS ${param}
SELECT
NON EMPTY {[Measures].[x]} ON COLUMNS
FROM [TRANSACTIONS];
Does it function?
If it does not function then the question is not really mdx related - as for some reason your syntax or the way the parameter is moving to the client is wrong.
note
The above is the equivalent of this super simple script:
WITH
MEMBER [Measures].[x] AS "hello world"
SELECT
NON EMPTY
{[Measures].[x]} ON 0
FROM [Adventure Works];
Do you have AdvWrks cube? Try these:
WITH
MEMBER [Measures].[x] AS "I'm not empty"
SELECT
{
IIF
(
(IsEmpty([Measures].[x])) //<< this returns False
,[Product].[Product Categories].[Category].MEMBERS
,{[Measures].[x]} //<< this is what IIF returns
)
} ON 0
FROM [Adventure Works];
It returns this:
Now I tested out IsEmpty:
WITH
MEMBER [Measures].[x] AS "I'm not empty"
SELECT
{
IIF
(
(NOT //<< added this to check functionality of IsEmpty
IsEmpty([Measures].[x]))
,[Product].[Product Categories].[Category].MEMBERS //<< this is what IIF returns
,{[Measures].[x]}
)
} ON 0
FROM [Adventure Works];
We get the following:
What I think is happening in your scenario is this - the param is not empty but is actually a zero length string:
WITH
MEMBER [Measures].[x] AS ""
SELECT
{
IIF
(
(
IsEmpty([Measures].[x]))
,[Product].[Product Categories].[Category].MEMBERS
,{[Measures].[x]} //<< the zero length string goes to here
)
} ON 0
FROM [Adventure Works];
Results in:
I'm working on my colleague's old project and I found on her code WHERE TRUE AND ID='1' AND STAT='1'.
I've tried to removed TRUE AND so the query become WHERE ID='1' AND STAT='1' and get the same result.
I know we can use TRUEas boolean to search 'where something is true' such as WHERE FLAG = TRUE and this MySQL documentation state that
The constants TRUE and FALSE evaluate to 1 and 0, respectively. The constant names can be written in any lettercase.
I also tried SELECT * FROM MYTABLE WHERE TRUE but it's just the same as SELECT * FROM MYTABLE
what is the purpose of TRUE in her query?
It has no specific functional purpose. Your colleague may have included it if they were adhering to a specific style guide that recommends that all SELECT queries have explicit WHERE clauses. If an explicit WHERE clause is not provided, the default is to select all rows. Adding a WHERE clause that is always true will have the same effect.
Another way this query could have come about is if it was generated by a code generation tool that always had to write in a WHERE clause due to the way it was written.
for example:
myQuery = "SELECT X FROM Y WHERE " + ConditionMet(data)?" AccountID = '" + AcctId + "'" : "1=1";
This means that if ConditionMet(data) is true, then only return rows where AccountID matches the AcctId you are passing in. If it is false, then return all rows.
Adding a "dummy" 1=1 makes the code generator simpler to write. More generally, 1=1 is as legitimate a boolean clause as any other, and can be "dropped" into a conditional expression without having to special-case the query to omit the WHERE clause.
Similarly, adding a WHERE clause that is always false (e.g. "WHERE 1=0") will result in zero rows being returned.
Do note that the example code here is vulnerable to SQL Injection, so it should not be used in cases where you are dealing with AccountID's that you did not produce yourself. There are multiple ways to secure it that are beyond the scope of this answer.
If you're writing your SQLString on runtime, and you might add different "where" clausules but you don't know which of all of them will be the first, it makes it easy as all of them may start with "AND ....."
Example:
SQLString:='SELECT * FROM YOUTABLE WHERE TRUE'
If condition1 THEN SQLString:=SQLString+' AND Whatever=whatever';
If condition2 THEN SQLString:=SQLString+' AND Whatever=whatever';
If condition3 THEN SQLString:=SQLString+' AND Whatever=whatever';
If condition4 THEN SQLString:=SQLString+' AND Whatever=whatever';
otherwhise, you should add the WHERE clause not on the first SQLString:= but on the first condition that happens to be true, which you don't know will it be a priori
it is not as much relevant but if find important where adding dynamic conditions,for example in php.
$condition_stmt="";
if ($start_date !="" && $end_date!="")
{
$condition_stmt="and nos.status_date between '".$start_date."' and '".$end_date."'";
}
else if ($start_date!="")
{
$condition_stmt="and nos.status_date >='".$start_date."'";
}
else
{
$condition_stmt="and nos.status_date <='".$end_date."'";
}
$sql="select * from table where true ".$condition_stmt=.";
I have a field with below expression:
=join(iif(Parameters!FUP_Letter.Value = 1, "Yes", "No"), ", ")
When the report is loaded the field only says '#Error' instead of 'Yes, No', 'Yes' or 'No'
When I remove the IIF clause from this expression the result is just '1, 0' or '1' or '0'
As I am still new to SSRS I don't really know what I did wrong or how to find what I did wrong so if anyone could tell me the error or help me on my way I would be very grateful.
Kind regards
I suspect the error is being caused by you trying to join one value to nothing.
The IIF function isn't recursive, so it will return for the first value that you return so in the case above it will exit after evaluating 1 and returning yes. The join function then try's to join 'yes' to nothing and therefore errors.
you could do something like:
=Join(Replace(Replace(Parameters!FUP_Letter.Value,"1","Yes"),"0","No"), ",")
Actual used:
=Replace(Replace(join(Parameters!FUP_Letter.Value, ", "),"1","Yes"),"0","No")
Please I need your help 4 days i'm searching about solution for this error i have this code :
SELECT NON EMPTY { [Measures].[T POND], [Measures].[FACT TABLE Count],
[Measures].[disponibilite], [Measures].[POND], [Measures].[T] }
ON COLUMNS, NON EMPTY { ([DIM AXE GEO 2].[VILLLE].[VILLLE].ALLMEMBERS ) }
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM (
SELECT (
STRTOMEMBER("[dim_date_Debut].[PK_Date].&["+ Format(CDate(Parameters!FromDimDateDebutPKDate.Value),
"yyyy-MM-dd")+"T00:00:00]") : STRTOMEMBER("[dim_date_fin].[PK_Date_fin].&
["+Format(CDate(Parameters!ToDimDateDebutPKDate.Value),"yyyy-MM-dd")+"T00:00:00]"))
ON COLUMNS FROM [CubeDispo])
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
This is the error when i deploy
query execution failed for dataset 'dataset1' query(4,93) Parser: the syntax for '.' is incorrect
Thank you in advance
Is something wrong with your parameter replacement in SSRS? It looks like maybe they are not being passed down? When I change:
STRTOMEMBER("[dim_date_Debut].[PK_Date].&["+ Format(CDate(Parameters!FromDimDateDebutPKDate.Value),
"yyyy-MM-dd")+"T00:00:00]")
To
STRTOMEMBER("[dim_date_Debut].[PK_Date].&[2010-01-01T00:00:00]")
The syntax is fine.
Firstly, run SQL Server Profiler, do an Analysis Services trace and capture the MDX that is being sent to SSAS from SSRS.
If the "Parameters!ToDimDateDebutPKDate.Value" is still in the MDX, then check how your parameters are being assigned to the dataset.
I see you are doing string concatenation to form your query. Make sure you use = operation to tell RS that its not a static query but an expression.
For example if i use this as a query in query designer, i would get an error.
"Select * from table where col =" & Parameters!FromDimDateDebutPKDate.Value
while the same thing with = operator before it becomes an expression which RS would evaluate before sending it to SQL
="Select * from table where col =" & Parameters!FromDimDateDebutPKDate.Value
Can anyone tell me how to display all the selected value of my multi value parameter in SSRS report. When giving parameter.value option it gives error.
You can use the "Join" function to create a single string out of the array of labels, like this:
=Join(Parameters!Product.Label, ",")
=Join(Parameters!Product.Label, vbcrfl) for new line
I didn't know about the join function - Nice! I had written a function that I placed in the code section (report properties->code tab:
Public Function ShowParmValues(ByVal parm as Parameter) as string
Dim s as String
For i as integer = 0 to parm.Count-1
s &= CStr(parm.value(i)) & IIF( i < parm.Count-1, ", ","")
Next
Return s
End Function
Hopefully someone else finds this useful:
Using the Join is the best way to use a multi-value parameter. But what if you want to have an efficient 'Select All'? If there are 100s+ then the query will be very inefficient.
To solve this instead of using a SQL Query as is, change it to using an expression (click the Fx button top right) then build your query something like this (speech marks are necessary):
= "Select * from tProducts Where 1 = 1 "
IIF(Parameters!ProductID.Value(0)=-1,Nothing," And ProductID In (" & Join(Parameters!ProductID.Value,"','") & ")")
In your Parameter do the following:
SELECT -1 As ProductID, 'All' as ProductName Union All
Select
tProducts.ProductID,tProducts.ProductName
FROM
tProducts
By building the query as an expression means you can make the SQL Statement more efficient but also handle the difficulty SQL Server has with handling values in an 'In' statement.