Why isn't custom SQL table column selectable/joinable in Tableau? - sql

I have a custom SQL table I make in Tableau as a stand-alone datasource
SELECT SUM(AMOUNT)/100 AS MONTHLY_REWARDS,CLINIC_ID,DATE_TRUNC('month',INSERTED_AT) AS MONTH,'Total Amount' AS TYPE
FROM "MY_SCHEMA".REWARDS
WHERE CLINIC_ID IS NOT NULL
GROUP BY CLINIC_ID,MONTH,TYPE
I'm not modifying or casting CLINIC_ID in any way in this summary. Yet when I access this field in a workbook I can no longer use it as a User Filter, but I can for MONTH or TYPE from my summary.
And when I use just the REWARDS table as the datasource (no custom SQL), it has no trouble using it as a User Filter.
I've tried right-clicking in the Worksheet and converting to string.
When I do, it becomes a User Filter option, but using it as a filter results in no data (because it is actually an Int in the data). When I convert it back to Number (decimal), it is no longer a User Filter.
Finally, if I try to have the custom SQL with the rest of my tables and join on Clinic ID, it says the types do not match even though they come directly from the same table with no modifications.
What am I doing wrong and how can I start using Custom SQL as a table in these scenarios? I'd like to be able to use Clinic ID from the Custom SQL as a User Filter as well as a key to join to other tables if I want.

Related

MSAccess Query Against Multivalued Field with Bogus Condition

I am trying to create a report in Microsoft Access that allows a user to select a variety of criteria from a form (including the option to not select any options for a specific criteria, resulting in no restriction on that field), which are then used as criteria in the record source on the report. I have been successful in doing so with all but two of my criteria, which are querying against multi-valued fields (The user selects a single option from the combobox, but the table being queried allows for multiple values in the field).
The control source for my combobox ("OSHA Carcinogens") is as follows:
SELECT
TblCarcinogens.ID,
TblCarcinogens.[Carcinogen Name]
FROM TblCarcinogens
UNION
SELECT
Null AS AllChoice,
"(All)" AS Bogus
FROM TblCarcinogens
ORDER BY TblCarcinogens.[ID];
The relevant code from my where clause is as follows:
((IIf([Forms]![FrmRPIFilters]![OSHA Carcinogens] Is Not Null,
[RPIMaster].OSHA Carcinogens].[Value]=
[Forms]![FrmRPIFilters]![OSHA Carcinogens],
[RPIMaster].[OSHA Carcinogens].[Value]=
[RPIMaster].[OSHA Carcinogens].[Value]))
<>False));
This method seems to work for anything other than multi-valued fields, but also seems pretty convoluted. I'm open to suggestions about streamlining the where clause in general as well if there is a better way to do it.
When the query is run with an option selected in the OSHA Carcinogens field on FrmRPIFilters, the result set includes only records which have no value stored in this field.
Does anyone have experience with this type of where clause and know what I'm missing?

Dynamic Parameter in Power Pivot Query

We are using Excel 2013 and Power Pivot to build modules that consist of several Pivot tables that are all pulling data from the same Power Pivot table, which queries our T-SQL data warehouse.
In an effort to simplify and fully automate this module, we wanted to create a text field that would allow a user to enter a value (a client ID# for example), and then have that value be used as a parameter in the Power Pivot query.
Is it possible to pass a Parameter in the Power Pivot query, which is housed in a text field outside of the query?
You can also pass a slicer or combobox selection to a cell. Define a name for that cell. Put that cell (and others if you have multiple text variables to use) in a table. For convenience, I usually name this table "Parameters". You can then 'read in' the parameters to your query and drop them in your query statements.
The code at the top of your query to read these parameters in might look like...
let
Parameter_Table = Excel.CurrentWorkbook(){[Name="Parameter"]}[Content],
XXX_Value = Parameter_Table{1}[Value],
YYY_Value = Parameter_Table{2}[Value],
ZZZ_Value = Parameter_Table{3}[Value],
Followed by your query wherein instead of searching for, say a manually typed in customer called "BigDataCo", you would replace "BigDataCo" with XXX_Value.
Refreshing the link each time a different customer is selected will indeed be a very slow approach, but this has worked for me.
Rather than pass a parameter to the data source SQL query, why not utilize a pivot table filter or slicer to do allow the users to dynamically filter the data? This is much faster than refreshing the data from the source.
If for some reason you need to pass this directly to the source query, you'll have to do some VBA work.

SSRS 2008 Add value to parameter resultset

We implemented a new system. Read-only access to the database. Writing reports for current and historical data. Using drill through report to display location and number of people there. Select the count of the location and go to details.
I query the location table to populate a parameters values. This works properly.
What I want is to ADD "Pre-Implementation" to the Parameters result set to cover the NULLS that exist because the data was before the implementation date. The phrase needs to appear in the drop-down list of locations so the user can select it. The phrase listed above needs to appears on the report. How would you do this?
What I have tried:
Have query that returns "Pre-Implementation" along with active locations for the time period. SSRS will not display as a choice in a drill through report.

Create SQL String in Microsoft Access Dynamically

I apologize if this is an easy one, but I can't find this on the web anywhere!
I have a list of tables and queries, and a full list of fields from each table and query.
I want to choose my fields in an Access form, and then, on another form, choose a query/table in one column (along with a field) and join it to a table/query in another column (along with the field.) My form for the joins would look like this:
Object1 Field1 Object2 Field2
and so on. I would want to be able to choose my fields through combo boxes, THEN make the SQL string dynamically. I can't use a where clause -- it has to be a join.
The problem is, the structure will change every time. Access gets funny about putting in parentheses. Also, if an object is chosen more than once, Access will want to join it (assuming I do it right) in a different manner than T-SQL.
Is there a way to write a query in T-SQL, and quickly convert to Access? Does anyone know the FROM clause algorithm Access uses to construct the FROM clause? I am stuck here, and I cannot find a solution to save my soul! Thank you in advance, David

Edit Parameter Field Crystal reports with NOT value?

In Crystal Reports, I want to add a WHERE field <> date to filter out dates that have a NULL value from my database in my report.
I'm using a legacy FoxPro database on the backend which generates an SQL statement from my report, but doesn't appear to have anyway of adding a WHERE clause to the generated statement.
When accessing the FoxPro backend directly, dates with psudo-NULL values have a date of 1899-12-30, but when they are pulled from FoxPro through Crystal they appear as 12/30/99 (which is maybe the same date just displayed in MM/DD/YY format).
I noticed that the report had an existing Parameter Field that prompts the user to filter out the original query down to a specific date range. I tried to add my own in addition to the Parameter Field, but discovered that what I needed with my WHERE field <> date is not an available option since there are only 3 types of Field Parameters mainly:
Discrete
Accept single and discrete values.
Ranged
Accept a lower and upper value in order to select everything in this range.
Discrete and Ranged
A combination of the two above
None of these appear able to filter the results of the query using a WHERE NOT type of clause, is there some other way to do this?
Add this to your record-selection formula:
// remove actual nulls
AND Not(Isnull({table.date_field}))
// remove old dates
AND {table.field} <> date(1899,12,30)
// remove dates not in select parameter value
AND {table.field} IN {#date_parameter}
All I really needed to do was add some criteria to the WHERE clause of the SQL statement, simple enough in an SQL client, but when you're doing this in Crystal Reports v10 it's a bit difficult to find, unless you know what you are looking for...
So what I needed to do was:
Select the field to filter by in the report (in the Details section)
Click the Select Expert button on the Experts toolbar.
In the Select Expert dialog the name of your field should appear in a tab.
Below you can select the WHERE criteria used to filter the records.