Bit conversion not working in SSRS report - sql-server

I'm working on SSRS report. I have Dataset that returns below values.
Now I wanted to change color of Data field on bases of this bit.
I tried below, but no success. It always shows False in report.
=IIF(CBool(Fields!IsAuthorized.Value)=True,"Blue","Black")
=IIF(CInt(Fields!IsAuthorized.Value)=1,"Blue","Black")
=IIF(Fields!IsAuthorized.Value=1,"Blue","Black")
Below Image show IsAuthorized.Value on data field.
Please help me!

Have a look here..
http://www.sqlservercentral.com/Forums/Topic1459800-1063-1.aspx
For example:
=IIF( Fields!IsState.Value <> 0 and Fields!RegionID.Value <>"12","Yes","No")
So yours should be something like:
=IIF( Fields!IsAuthorized.Value <> 0 ,Black,Blue)
This should cover it.

Issue was with while I was passing the value to Dataset to fetch rows.
SELECT DISTINCT Number,
[dbo].[Function](#UserID) AS IsAuthorized,
FROM TableName
Here, #UserID always passed as blank from my web application and this is why conversion gets failed.
I changed my below line of code in web app to set it's correct value.
Before
ReportParams.Add(new ReportParameter("UserId", Request.QueryString["UserId"].ToString()));
After
ReportParams.Add(new ReportParameter("UserID", Request.QueryString["UserID"].ToString()));
Also, I have set Default values for #UserID in Parameters properties as blank. This is why also it was causing issue.

Related

SSRS Is Not Properly Displaying Query Results

When I run my query I get the following result.
' 200515200517 10'
This value is stored in varchar field in the table I am pulling from.
When I add this field to my report it is displaying the following:
' 2:00AM200517 10'
What do I need to do so the report will display the actual results and not change the value to a time. Any help will be greatly appreciated.
After playing around I found my issue. I am passing a date parameter as part of the query. I added some formatting logic on the parameter and that resolved the issue.

How to retrieve a parameter value that's not set in the report?

I'm working in report builder, calling a stored procedure that has a parameter that, when null, sets itself to a certain value. I want to display what this parameter is set to on the report. From experimenting, Report Builder's parameter collection only shows the parameter as it is sent from the report.
Alternatives that I've considered but can't get to work or are sub-optimal:
Adding the parameter to the select statement. The main drawback is this won't display a value if there are no results.
Using a return value or output parameter. There doesn't seem to be a way to do this.
Re-creating the "null" logic in the stored procedure. The correct output is displayed but this is a code fork.
How can I display this value? Is there a way to show a return value or output value?
You could change the procedure to return the parameter value in a UNION ALL select so that a row with the parameter value will always be returned. That row could have NULL for all the other columns so that you can filter it out in the rest of the report.
Another possibility is to add a second dataset to the report that does nothing but get the value of the parameter based on what you pass. That, however, is also a sort of code fork. The fork could be mitigated, however, by putting it in a UDF, and resourcing the same UDF in both datasets.
Yet another possibility is to replicate the logic of populating the parameter in a Custom Code block in the report. However, that is also a code fork.
I've never worked in Report Builder interface but I do have quite a bit of experience building reports in BIDS/VS... There it's a simple matter of setting the parameter default, in the rdl, to match the default in the stored procedure.

Using Parameters in SSRS with LIKE operator

I am trying to create a report that has a list of various product groups as parameters. When selecting each group, a list of those related products should appear. I am currently getting a blank table.
The results for this product group display when i execute the query.
I have the list of parameters and values as follows:
i'm struggling to see where I have gone wrong, when i preview the report, I can select each parameter, but get an empty table in the report. I expect the way I have given each parameter a value may be the problem, but cannot figure it out.
This is the query in the report.
DECLARE #ProductCode VARCHAR(12)
SELECT STRC_CODE, STRC_DESC FROM DeFactoUser.F_ST_Products
WHERE STRC_CODE LIKE #ProductCode
I am using Visual Studio Data Tools 2012 to build the report.
If anyone could give me a clue, that would be greatly appreciated.
It doesn't work without the quotes. I thought the quotes and wildcard
would be necessary to allow the LIKE operator to work.
First of all you don't need to use quotes, I tried to reproduce it right now and it works without quotes:
Second, the query that SSRS sends to server looks like this:
exec sp_executesql N'select model
from [dbo].[cars]
where model like #car',N'#car nvarchar(3)',#car=N'ca%'
So the only thing it changes respect to your code is parameter type, it always declares it as unicode, i.e. nvarchar(...), so maybe it make sense to try in SSMS your code with parameter type changed to nvarchar(12):
declare ProductCode nvarchar(5) = N'PA.A%'
Try to execute it in SSMS and see if it returns smth or not

SSRS - Show textbox if string contains numbers

I am trying to convert the following SQL Server expression into a visibility expression in SSRS for a certain textbox that contains an error message:
select address, commonPlaceName, municipality where #Location not like '$[0-9]%'
My SSRS report lets users search for #Location, which is a combination of the address and commonPlaceName and returns a table of records.
I am trying to limit the number of rows returned based on both the character length and whether the parameter value supplied contains a number.I want to show an error message when they search for a common place or address without a number that says "Sorry your search was too broad so the number of records has been limited".
I got the length part to work by using the following:
=iif(len(Parameters!Location.Value)<=5,false,true)
But I can't figure out how to search for a number in a string
For those interested, in the SQL script, I am setting the rowcount based on a case statement that parallels the visibility options I am trying to set in SSRS.
I am still learning SSRS so any help is much appreciated!
EDIT:
Below is the SQL statement I am using to limit rowcount if that helps:
declare #top int
set #top = case when len(#Location) <= 5 then 100
when #Location not like '%[0-9]%' then 100
when len(#Location) >5 then 0
end
set rowcount #top
There are a number of ways to do this.
Calculate the visibility in your query and set the Visibility to the calculated query field. This is cleaner in the report. Normally you would want to put all display logic in the report itself, however, I have been lazy a time or two.
=IIF(Fields!ShouldShowField.Value==1,0,1)
Use SSRS functions such as InStr() or
=IIF(Regex.Replace(Fields!MyField.Value, "[MyRegExString]").Length == Fields!MyField.Value.Length, 0, 1)
Use Custom Code for advanced string manipulation and call your code similar to
=IIF(Code.ShouldShowTextBox(Fields!MyField.Value),0,1)
Okay I think I found a workaround for now. I ended up creating a new dataset:
select
'LocationWithNum' = case
when #Location like '%[0-9]%' then 'true'
else 'false'
end
Then I changed the visibility expression of the error message textbox to the following:
=iif(len(Parameters!Location.Value)<=5 or First(Fields!LocationWithNum.Value, "LocationWithNum") = false, false, true)
So far this seems to work well. Let me know if you guys think of anything else!

Hide Columns Based on parameter value not working in SSRS

I have a SSRS report which have N number of Columns. I need to hide Certain columns based on a parameter "jobcode" . I have tried below expression in Column Visibility Pane,
=iif(Parameters!JobCode.Value=1,"False","True")
While Executing the report I got below Error,
"The Hidden Expression used in the tablix 'Tablix1' returned a
datatype that is not valid"
I have tried like below,
=iif(Parameters!JobCode.Value=1,0,1)
But, got the same error. Can Anyone help me to find out answers for below queries
How to achieve the above requirement in ssrs?
If I need hide column based on multiple parameter values, say 0 and 1, How to do it?
Thanks for the help.
If JobCode = 0 , Show
=IIF(CInt(Fields!JobCode.Value) = 0,true,false)
Try this.
Follow these steps:
Right click in your column>Column Visibility>Show or hide based on an expression
Expression, use that:
=Parameters!parameter_name.Value<>1

Resources