What could cause a drop down list (select) to ignore its Value field? - ssrs-2008

I've got a report that has several parameters, among them CompanyID. The available values come from a dataset with the Value field set to "Value" and the Label field set to "Label". Not exactly Rocket Science. The query looks like this:
select null as Value, ' Any' as Label
union all
select CompanyID as Value, CompanyName as Label from core.Companies
order by Label
Ok, no surprises. When I run that query I get things like
1506 Amalgamated Steel
2341 Beson Industries
245 Carver Holdings
etc....
Looks fine. However, when I view the HTML generated in report viewer, the select element that is generated has ordered integers for values: 1,2,3,4 etc. so filtering the results by company ID isn't working.
What could cause this? The query is returning the correct values, the values are being populated in the dropdown, the Value field for the param is set to the Value field from the query. They just don't have the correct value in the select/option field.

I cannot reproduce this in reporting services, it is working exactly fine for me.
My query is similiar although I always want the value "All" or "Any" as you mentioned to be at the top of my list so users dont have to look for it. I also do not include null as a value, I translate null to the value 0:
SELECT
1 As SortOrder,
CompanyID as Value,
Company as Label
FROM
Core.Companies
UNION ALL
SELECT
0 as SortOrder,
0 as Value,
"All" as Label
ORDER BY
'bring all / any to the top
'then order the rest by company name
SortOrder,
Label
This ensures the null is not included in the result list...then in my main query the query that pulls the data, when I want to filter for the company id or all I do this:
SELECT
...
FROM
Mytable
WHERE
CompanyID = #CompanyID OR #CompanyID = 0 'handle one customer or all customers
The report works fine and my select has the correct values...

Related

One field in a Crystal Report with a different Select than the rest of the report

I have a table that has a primary key which is a combo of 2 fields:
ITEM_NO and
LOC_ID
I have a a report made that shows me all the results of an ITEM_NO based on LOC_ID that is chosen. So lets say for all items, show me all the fields I need to see where LOC_ID = '1'
This is set up in the select record section, however, there is one particular field (BIN_1) per record that I want displayed which should show me the value based on LOC_ID = '3', no matter which LOC_ID is set in the select expert parameter.
So, even though all the fields on the report show values Where LOC_ID = '1', the BIN_1 field should show the value where LOC_ID = '3' regardless of the parameter set for the rest of the report
I tried this by creating a new formula field in the report with a where clause, but this doesnt seem to work. Anyone here have any better ideas
You may add the table you are selecting from a second time to your report. Maybe rename it to something like "table_loc3". (Inner-) Join "table_loc3" to your original table on ITEM_NO. Add a record selection criteria for "table_loc3" and filter LOC_ID to be 3.

Finding median value per category

I have a data table with columns "field" and "conc" (which is short for concentration). I am trying to output the each type of field (the categories are cosmos, egs etc) along with the associated median value of the conc statistic for each field type.
This is what I have tried:
SELECT field, percentile_cont(0.5)::numeric FROM galaxies GROUP BY conc LIMIT 5;
ERROR: function percentile_cont(numeric) does not exist
LINE 1: SELECT field, percentile_cont(0.5)::numeric FROM galaxies GR...
However, I am getting this error and am not exactly sure how to go about extracting the field name with the median value for conc for each field type
As indicated in the documentation for PostgreSQL, WITHIN GROUP (ORDER BY...) is mandatory for the ordered-set aggregate functions like percentile_cont.
If you want the median of the conc, then grouping by conc is surely the wrong thing to do. So you might want something like this:
SELECT field, percentile_cont(0.5) within group (order by conc)::numeric
FROM galaxies GROUP BY field LIMIT 5;

How to sort combo box by frequently used?

So, simple question, I have combo box in my database and I want items that I have selected most frequently to appear first the next time that I add a record.
I would suggest adding a Long Integer field to the table consituting the row source for your combobox, and incrementing the value held by such field either on the AfterUpdate event of the combobox, or following the main operation being performed by your form.
Then, sort the items in the combobox by this new field in descending order.
I assume that your combo box selects a lookup value in for a property (PropertyID) that is saved in a table (MainTable).
You can get the number of times this property has been selected with
SELECT PropertyID, COUNT(*) AS SelectedTimes
FROM MainTable
GROUP BY PropertyID
Now get the sorted lookup table by using this query as sub-query:
SELECT L.PropertyID, L.Name
FROM
LookupTable L
( SELECT PropertyID, COUNT(*) AS SelectedTimes
FROM MainTable
GROUP BY PropertyID) X
ON L.PropertyID = X.PropertyID
ORDER BY X.SelectedTimes DESC, L.Name
I'm also sorting by name in case two entries have the same count.
As usage may change over time, you should record the time when an item was selected. Then you can weight the usage, so recent usage of an item have higher weight than those items used, say, a year ago.
Then you can run a query to list the usage having the most recently used items at top:
Select Item, Sum(1 / DateDiff("h", [SelectedTime], Now())) As Usage
From ItemUsage
Group By Item
Order By Sum(1 / DateDiff("h", [SelectedTime], Now())) Desc
Of course, this linear weighting may be too simple. You can apply any math to the usage like square or log.

SSRS report parameters

In my SSRS report there are 2 parameters called DataSourceIDList and ReporterIDlist.
DataSourceIDList : is a drop down list and this will populate based on SQL query.
ReporterIDlist : is a drop down list and this will populate reporters based on selected Datasourceid from DataSourceIDList and this is also a SQL query.
both parameters are optional fields but when i am running the report i am getting error called "Please select value for DataSourceID" but i set the property for that parameter as allow NULL values
and same problem for ReporterIDlist also.
Please suggest your suggestion....
Thanks in advance...
I think that SSRS will not allow you NULL value if parameter have datasource.
Trick that I do when I need all values that is: I change data source for parameters that is in list have
null, or ( 0) value, and option select ALL, and after that I set default value to null so users do not have to touch parameters before it call it
Something like this,
Select 1,null as ValueOfParam,'All values' as TextOfParam
union all
select 2,id,name from myDatasourceThatHaveParamValues
order by 1,name
to verify date, you can use this method too:
make two rectangle; insert table/matrix in first rectangle
in second rectangle insert msg like
"Selected Date is not valid, please select correct date"
or "Start Date should be less less than End Date"
put appropriate msg, and make condition in 1st rectangle where all tables/matrix is there
iif( Parameters!StartDate.Value < Parameters!EndDate.Value,false,true)
in second rectangle where Error msg is inserted write this:
iif( Parameters!StartDate.Value < Parameters!EndDate.Value,true,false)

How to show empty groups in crystal?

I have a report that shows items by goups.
Lets say he groups are:
In Inventory
In Process
When there is no data In Inventory, that row is not shown. any idea how to show a row with 0 inventory?
It sounds as though you are grouping on a field (such as stock item status), where there may be 0 rows returned for certain values of the field (such as In Inventory). The answer is to amend your query to right outer join to a lookup table holding all values of the grouping field, for example as follows:
select lu.status_value stock_item_status,
si.stock_item_status item_status,
si.stock_item_id,
coalesce(si.quantity,0) quantity
from stock_item si
right join stock_item_status lu
on si.stock_item_status = lu.status_value
This will now include a row returned for stock_item_status values with no corresponding stock_items, with null values for all of the stock_item fields.
If you were including a subtotal of stock_item.quantity values for each status, changing this to coalesce(...,0) should ensure that this null value is displayed as 0.
If I'm understanding you correctly, you've got a field {table.inventory} that holds the number of items in inventory that has a null value when the inventory is zero? When you group on this field you're not seeing the rows with null values in this field?
Crystal should still display those rows, just in a group with a null group name. To fix this you can go into the Group Expert -> Select the group in question -> Options -> Options tab -> Select 'customize group name field' -> and then specify a formula as a new group name field where you simply check to see
if isnull({table.inventory}) then 0 else {table.inventory}
Similarly, you can just create a formula that does this and group on that instead.