SSRS Multi Select Parameter, both Null and not null - reporting-services

I'm new to SSRS, and have been tasked with a report that allows users to select NULL, non NULL or both.
For example
Name | ID
BOB 1
ALICE 2
DAVE NULL
ROGER NULL
Users need to be able to select Records with an ID value and/or records with no ID value.
So it would be a multi select parameter (ID, NO ID , ALL).
I can make this work with a sql query, but am not sure how to make it work with user parameters that can be either, or or both.
The id field is a decimal.
Any advice for how to do this?
Thanks.

One way would be to include conditions like the following in the WHERE clause:
and (ID is null and 'NO ID' in #Parameter or
ID is not null and 'ID' in #Parameter)
Alternatively, if the non-null ID values are always positive, you could use "NO ID" and "ID" as the parameter value labels, with the actual available values as 0 and 1 respectively, and use a condition like:
and sign(coalesce(ID, 0)) in #Parameter
(These conditions won't work in conventional SQL - where #Parameter will always be single-valued - but should work in SSRS.)

In the general tab of your Report parameter. There is an option for Allow Null Values. Check that box.
Also update your query to
From UserTable
Where (ID IS NULL OR ID IN (#IDparam))
Here are links if you need to know more abut Multi Select parameters
http://jsimonbi.wordpress.com/2011/01/15/using-multi-select-with-stored-procedures/
http://technet.microsoft.com/en-us/library/aa337396(v=sql.105).aspx

Related

Issue flagging a "difference" between 2 data fields using an IIf statement in Access query when one value is Blank/Null

I have 2 tables with "like" fields and am simply trying to "flag" all records where the "like" fields are different. For example, I have a description field in table #1 and a description field in table #2.
I created a new field titled Description_Diff with the formula Descr_diff: IIf([Tbl 1 items].[description]<>[Tbl 2 items].[description],"diff","").
The issue I am having is that if one of the two values is Null/Blank it does not return a "diff". I apologize in advance if this answer had already been covered, but upon searching the site was unable to find the answer.
Try with Nz:
Descr_diff: IIf(Nz([Tbl 1 items].[description])<>Nz([Tbl 2 items].[description]),"diff",Null)
The real answer is that you can't compare Null using any logical operator.
So If 1 <> Null doesn't work as a comparison.
Have a read here http://allenbrowne.com/casu-11.html and http://allenbrowne.com/casu-12.html for a fuller explanation.
use coalesce
usage:
coalesce(value, defaultValue)
when comparing if it's null, throw in "" or -1 as a default value, then comparing with blank or default would return false
Use the coalesce in your query in the select
Select coalesce(id,-1), coalesce(firstname,"") From myTable

Select values from not empty column in mysql

Table Photos-------
photo1 imagem1.jpg
photo2 imagem2.jpg
photo3 empty
photo4 empty
photo5 enpty
I have a table, with 5 columns who represents photos.
So,
I want to select * from table, all columns... but if one or more of them are empty, I don't want to select. is that possible?
For example, if I do this
Select * from table Photos where photo1 is not null, and photo2 is not null, and photo3 is not null and photo4 is not null and photo5 is not null
that is not possible, because if one of them are empty... the select don't give any values.
anyone know another way?
and also, i need that because if I want to do this:
the problem is.... when I use php for example this
if($project['photo5']!='' and $project['photo5']!=null){
(here i show the picture)
}
If the row is empty... php is ignored and show a error image
Concat() will return null if any one of the values concat is null (mySQL DOCS) Since you want to only show records where none are null concat together and check for not null.
Select *
from table Photos
where concat(photo1,photo2,photo3,photo4,photo5) is not null
AND... your approach should work if you used or's instead of AND and possibly a not. I just find the above easier to read.

SSRS - Limiting results using multiple parameters

I'm creating a debtor invoicing report which has two parameters.
Parameter 1: This is a single value parameter called #booking_date. I filter the results(main dataset) by adding this into the query as a query parameter.
Eg. WHERE BookingDate = #booking_Date
Parameter 2: This parameter has two specified values - Yes or No. The parameter is called #live_run and the default value is 'No'. Basically, when this parameter has the default value of 'No', it does not limit/effect the results in any way. On the other hand, when this parameter has a value of 'Yes', it should limit the results by only displaying the bookings where the invoice has been paid off. There is a field I can use for this called Booking_Paid_off as follows - WHERE Booking_Paid_Off = 1.
I have parameter 1 in place, but I am unsure how to bring in Parameter 2 because it will be based on two conditions, do I need to use an If statement or a case statement? Do I need to create a new dataset for the second Parameter? I only want to limit the results with Parameter 2 ONLY if Parameter 2 has a value of Yes, otherwise I want the results to stay the same.
You have many options. You can switch out the Dataset entirely based on the parameter or use an IF inside the dataset to determine which query to run or simply check the parameter in your WHERE clause.
I recommend the latter.
SELECT
Field1,
Field2
FROM
Table1
WHERE
(
(#live_run = 'Yes' and Booking_Paid_Off = 1)
or (#live_run <> 'Yes')
)

Inserting NULL value to MySQL, from Coldfusion

I have a database that may have a value in one of the fields. Circumstance may need to remove the initial value and replace it with a NULL.
How can NULL values be inserted in an empty field?
Appreciate it.
You'd write a query that's something like this:
<cfquery name="queryName" datasource="dsn">
UPDATE tableName SET fieldName = NULL
WHERE recordId = <cfqueryparam cfsqltype="cf_sql_integer" value="#recordId#" />
</cfquery>
Also, there's a difference between a blank string and a NULL value. The thing to remember about NULL is that it doesn't equate to anything but NULL. But it also doesn't equate to non-NULL values. So if you have three records in your table:
ID VALUE
1 15
2 NULL
3 30
When you run this query:
SELECT ID from tableName where value != 15
you will ONLY get record 3. The way to make sure record 2 is included in the resultset is to alter your query as such:
SELECT ID from tableName where coalesce(value,16) != 15
The purpose of coalesce is to check the first parameter for NULL-ness, and use the value of the second parameter instead if the first parameter is NULL. In the above example, I've put '16' as the second parameter, but you can use any value you want as long as it's not the same as what you're comparing for (in this case, 15).

null used with logical operator

I have a table with name,age and address.I have totally five rows of data in the table.For some rows the age is left null.I have to display all the data where age is not null.
select * from sample_table where (age !=null);
But no output is displayed and it doesn't give an error also.Please explain this.Thanks.
With NULL you have to use IS or IS NOT. The following query should work:
SELECT * FROM sample_table WHERE (age IS NOT NULL)
The explanation from MySQL
The concept of the NULL value is a common source of confusion for
newcomers to SQL, who often think that
NULL is the same thing as an empty
string ''. This is not the case.
In SQL, the NULL value is never true in comparison to any other value,
even NULL. An expression that contains
NULL always produces a NULL value
unless otherwise indicated in the
documentation for the operators and
If you want to search for column values that are NULL, you cannot use
an expr = NULL test.
To look for NULL values, you must use the IS NULL test.
You have to use IS NULL or IS NOT NULL.
You can not compare directly against NULL because it is not value (no pedants please!)
NULL on Wikipedia
MySQL, Sybase, SQL Server... it's all the same