SSRS Parameter to select a column name on value which to filter the dataset - tsql

I need to allow my user to select a column name and its value from a parameter (or two params) to filter the result.
I have a text parameter with a few column names that are listed in my dataset
Column1, Column2, Column3. Each of those columns has only two values 1 and 0.
I would love some help in getting an idea how to filter my dataset based on the column name listed in the parameter and a selected value (1 or 0)
I assume it has to be related to a dynamic sql but, not sure how to incorporate that in either the WHERE clause or the actual dataset filter.
Thanks for any points guys!! :)

In the tablix you can use the filter section to set the criteria
col1 = param1.This will only select the rows that match the value of the parameter.
https://www.mssqltips.com/sqlservertip/2597/dataset-and-tablix-filtering-in-sql-server-reporting-services/

Related

Create SQL Column Counting Frequency of Value in other column

I have the first three columns in SQL. I want to create the 4th column called Count which counts the number of times each unique name appears in the Name column. I want my results to appears like the dataset below, so I don't want to do a COUNT and GROUP BY.
What is the best way to achieve this?
We can try to use COUNT window function
SELECT *,COUNT(*) OVER(PARTITION BY name ORDER BY year,month) count
FROM T
ORDER BY year,month
sqlfiddle

Selecting a row by searching a specific value in an Array column

We have a table where one of the columns is an array. I need to select a row or many rows as long as my search value matches their values using ILIKE. My problem is that I need to search the values of an array column as well. I tried using ANY but the value needs to be exact to select a row. I need something similar to ILIKE but for that array column.
Thank you in advance.
Use unnest function:
SELECT x.value
FROM my_table t, unnest(t.my_array_column) as x(value)
WHERE x.value ILIKE 'foo'
Once your question is also tagged elixir, for converting this to Ecto use Ecto.Query.API.fragment/1 for the select condition and Ecto.Query.API.ilike/2 for match.

Manually pass multiple integer values to a SSRS sureport

I'm trying to pass multiple integer values to a subreport, in order to use the following SQL request :
SELECT *
FROM Table as T
WHERE Code IN (#Code)
I want to pass 3 integer values to #Code: 1,2 and 3
I tried to use various combination of Split() and Join(), but none worked.
You don't need to do anything. If your parameter is set to be multi-value and takes it's values from a query or list of integers then SSRS will automatically inject a comma separated list of values into your main dataset query.
In your case if values 1, 2 & 3 were selected and you main dataset looked like your example
SELECT *
FROM Table as T
WHERE Code IN (#Code)
then what actually gets passed to the server would be this..
SELECT *
FROM Table as T
WHERE Code IN (1,2,3)
There is no need to do JOINS or SPLITS and no need to change dataset parameters. It will just work.
When I use a multi-value parameter in SSRS I have to use a table-valued function in the query. Essentially, it turns your parameter into a table that you can INNER JOIN on. For example:
SELECT *
FROM Table as T
INNER JOIN tablevaluefuntion(#Code,',') as P--the ',' is the delimiter from your list
WHERE t.code = p.value

postgres query exclude search criteria by parameter

I have a table and 4 columns there. Also I pass 4 parameters to my query. For example, if I pass only one parameter equals true, I want only first column to take part is query
sth like
select * from mytable where (case when #mypar=true then **and field1=1** end)
I want AND clauses to be included by parameter. How to do that in postgres?

Getting Generated Always Columns list from DB2

Is there any way I get all column names and assoicated table names which has identity column set as generated always?
For I dentity columns I can simply use syscat.columns but how to fitler identity columns which has generated always vallue?
select identity, substr(tabname,1,30), substr(colname, 1, 30) from syscat.columns where tabschema='MYSCHEMA'"
From the above select list I wanted to filter only columns which uses generated values...
The online documentation for SYSCAT.COLUMNS. The two columns you're interested in are IDENTITY and GENERATED.
Your query will probably be something like:
SELECT TABNAME,COLNAME FROM SYSCAT.COLUMNS WHERE
IDENTITY='Y' AND GENERATED = 'A' AND TABSCHEMA='MYSCHEMA'