Filtering out results based on length of reference number - reporting-services

I have a report, in report builder, where I am getting duplicate rows based on the reference number.
In the below example, is there anyway that I can remove any reference number that is longer than 9 digits using an expression, I've looked into using LEN but cant seem to make it work for me! I am very new to SQL and report builder.

You can use a Filter on either the Dataset or the object (table, chart...).
The Filter Expression would be the LEN of you field - =LEN(Fields!HB-RENT-REF.Value)
The Type would be Integer.
The Operator would be <=.
And the Value would be 9.
This would only allow records with a HB-RENT-REF field length of 9 or less.
MS Docs: Dataset Filter

If you're using SQL scripts or procs to build your report, then you could simply include a WHERE clause that checks for if the length of your column, using the LEN() method, is less than or equal to your condition. So something along these lines:
SELECT *
FROM YourTable AS yt
WHERE LEN(yt.YourColumn) <= 9;
You will want to replace the * with the specific columns you want and use the appropriate tables too of course. But that's the general idea of checking for length in a WHERE.

Related

Filter Multivalue Parameter on Dataset

So I have a multiple value parameter than contains 3 options. >250K, <250K, >2M.
I also have a table that consists of multiple columns.
. Because the parameter is a multivalue, i am having difficulties filtering the dataset.
I need to filter the dataset by checking, (if > 250K is selected, filter the dataset accordingly), (if < 250K is selected, filter the dataset accordingly) and (if > 2M is selected, filter the dataset accordingly).
I was told to use a join and split on the parameter within the (>250K condition, then do a contains to see if it contains any of the parameter values) but I am not as advanced in my knowledge of coding to be able to do that.
Any Suggestion? Thanks in Advance
I previously tried the method below but then i came to realise that it wont work because the parameter is a multi value.
I know its been a while since you raised this, you were on the right track but all you should need to do is add a filter to the Tablix on the field you will be filtering, use the 'in' operator and in the Value type [#Yourparametername] the square brackets and case sensitivity are important. Also ensure the expression type is correct, in your case it looks like you are using Integer. The image should help.
If you want to use multi-parameters, In the dataset, you can read parameter value using JOIN.
Example:
If you want to read multiple values for #MyParamter in a dataset given in the following example:
Dataset Parameters
you need to use =JOIN(Parameters!myMultiParamter.Value,",") as an expression to read all selected values in CSV form.
Expression
Now the #ParameterValues param has all selected values as comma separated values and you can use them in your dataset code as per design requirements.
Note: It's not necessary to use a comma but u can use anything you want to separate values.
Your sql query where should look like
Where
(
(0 IN (#Parameter) AND ValueColumn<250000)
OR
(1 IN (#Parameter) AND ValueColumn>=250000)
OR
(2 IN (#Parameter) AND ValueColumn>=2000000)
)
One parameter
Two parameters
All parameters
Once you return the value you can also use charindex or patindex* and look for where the value in your where clause is a pattern where the index number is > 0 . For instance if the returned string from SSRS is '01,02,03' and then your where clause has something like this right(field, 2) which would result in value '03'. you change your where clause to be where patindex('%' + right(field, 2) + '%', #returnedstring) > 0 which will give you results. The keeps you from having to parse apart the #returnedstring parameter in your sql code.

Parameter Value to select project number range

I have a parameter asking the user if they would like to "only" include project numbers below 5000.
If they say yes, then I need the parameter to adjust the project field to be <=5000. If they say No, then the project number field should be <=99999999.
I am not sure how to accomplish this, right now I have a dataset where project number = #projnum, and I have #projnum parameter with two values of Yes and No.
I attempted to put an expression on the dataset properties under that specific parameter as:
=iif(Parameters!projnum.Value=1, <9999, <9999999999)
but I get a syntax error when using the < sign. It will work with just a number.
Sorry, new to SSRS and cannot figure this one out.
Why not change your dataset query to use <=:
SELECT *
FROM YourTable
WHERE ProjectNumber <= #projnum
Then adjust your parameter values to the range values:

Odd results in MS Access Query using a DSUM function and parameters

I've just started using MS Access this month and I have a very odd bug. I'm trying to create a query that searches for records in a table that have a maxBenefit (a dsum from a different table's field, with a one to many relationship) within a certain range. I'm using the DSUM function to get the maxBenefit because the table has a dailyBenefits field that need to be added together.
Here is my function:
maxBenefitOfQuote: Nz(DSum("[wholeYearBenefit]","tblDisabilityQuoteDailyBenefits",
"[quoteID] = " & [tblDisabilityQuotes].[ID]))
I know the function works because it produces the correct values. The query also takes in two parameters from a form to create a range for maxBenefits.
I limit the results with this criteria:
>=[Forms]![frmDisabilityFindSimilarQuotes]![minBenefitTotal] And
<=[Forms]![frmDisabilityFindSimilarQuotes]![maxBenefitTotal]
The problem is I get very odd results from the query with maxBenefits outside the range or not returning records with maxBenefits inside the range. If I set the minBenefitTotal to 0 and the max BenefitTotal to 100000000 I get no records returned from the query. If I set the minBenefitTotal to 0 and the maxBenefitTotal to 999999999 I get all the proper records.
Any ideas why this is happening? Thanks in advanced.
First,
Try wrapping both of your inputs in a call to CCur:
>=CCur([Forms]![frmDisabilityFindSimilarQuotes]![minBenefitTotal]) And
<=CCur([Forms]![frmDisabilityFindSimilarQuotes]![maxBenefitTotal])
Next,
If you omit the actual form inputs, and hard-code numbers into the criteria, does it work?
For Example: (>= 0 and <= 100000000)
If that worked... It feels like a string -> number conversion issue. Make sure all string input is actually a number (via CCur()) before sending it into the query.

Date field filter is not working in Row Group level filter

I have added a Filter in Row Group-> Group Properties to perform sum of quantity only for those transactions which have done before a certain date.
Whenever I am selecting the 'Cdate' as Expression field from my dataset1, the type is showing as Date/Time but after saving it when I check,I found it as 'Text'. As a result the filter for 'cDate' is not working during report generation.
Note that, I can't filter the data in dataset side or tablix side as I have to show all the column items. This is a matrix report.
OK this is going to be a bit confusing because your dataset contains a field with the same name as one of the built-in expression functions ("CDate" - Convert to Date).
I sometimes run into these datatype issues when using filters and I find the best way to handle it is to force both the filter field and the filter value to be the same data type.
So in your case try setting the Filter expression to:
=CDate(Fields!CDate.Value)
then select the operator as "<=" and set the value using an expression as well:
=CDate(Parameters!MyParameter.value)
and see if that works.
I understand you so that your date field in the dataset is called CDate, try casting it as date, so instead of selecting it in your filter, type the following into the filter
=CDate(Fields!CDate.Value)

calling a query from a report textbox

I have a report based on a number of different queries. Most of the queries use the value of a row's customerID textbox as a key to extract specific data from other fields.
Here is what I have for the Control Source property of one of the textboxes:
=DLookUp([Level],[qryLevel],[Me].[customerID])
Here is the SQL for qryLevel:
SELECT TOP 1 Level, myDate FROM sometable WHERE custID=Me.customerID ORDER BY myDate DESC
qryLevel works when tested independently, but the DLookUp function does not seem to be working properly because Access gives a dialog box asking for each parameter and then outputs #NAME? in the textbox when no values are input into the dialog boxes.
How can I get each of these textboxes to output its own result from a separate query?
DLookup function arguments must all be strings: http://allenbrowne.com/casu-07.html
So for the first two arguments, just enclose them in double-quotes.
For the last argument, the documentation says it's equivalent to a SQL where clause, without the word 'where'. Actually since you're returning only a single record from your query you probably don't need the last argument at all:
=DLookup("[Level]", "[qryLevel]")
Although, I don't see how qryLevel can work as an independent query since it refers to Me which implies a container object. Better to express as:
SELECT TOP 1 Level, myDate
FROM sometable
WHERE custID = [Forms]![MyForm]![customerID]
ORDER BY myDate DESC
... which will work in any context--inside or outside a form.