I'm using a PostgreSQL ODBC data source in an SSRS report.
From my previous knowledge with MS SQL Server data sources, to pass an optional parameter to a SSRS dataset query, you would do this:
SELECT *
FROM MyTable
WHERE SomeField = @Param1 OR @Param1 IS NULL
The key was using OR @Param1 IS NULL which basically bypasses the SomeField = @Param1 part and effectively acts as an "optional" filter. However, this doesn't seem to work when using a PostgreSQL ODBC data source (not sure if it's due to Postgres or ODBC or both). I get an error when clicking on Refresh Fields, or when executing/previewing the report.
This might be partly due to not being able to pass named parameters into the SQL, but instead having to use "?" like so:
SELECT *
FROM MyTable
WHERE SomeField = ?
...which makes it impossible to do OR ? IS NULL basically.
So, anybody know how I might be able to pass optional parameters to a PostgreSQL data set in SSRS?
WHERE (somefield = ? OR CAST(? AS <somefield's data type>) IS NULL). So, the CAST on the parameter?is necessary, otherwise the SSRS tooling gives you an error of unknown data type. And I have to use 2 parameters in the Data Set to refer to the same parameter twice (because of 2?references in the WHERE clause), but that's not terrible. Don't know why I didn't think of casting before. - Jiveman