SSRS Is Not Properly Displaying Query Results - sql-server

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.

Related

How to display a multi-valued parameter onto a SSRS report in a specific way, separated in ranges and/or commas

In SSRS I need to display a multi-valued parameter onto the report in such a way that if values are chosen in sequence they appear as: 1-5, 7, 9-10, 15 and so on. And I have the following values in my drop down list of values: from '0' to '200'.
Thanks in advance for your help.
This is what I have done in SQL so far, so I am thinking to update 'String_To_Use' column so it would display: 0000-1020, 1199-1210, 1260, 1299. Then use this string to display onto the SSRS report. These are the values chosen in SSRS from the drop down box. I don't know yet how I would pass these values to the SQL code yet. Please help with this part as well.
This is the #tempTable1...column 'DPRTMNT' has the values chosen ...Checking_Dept has the value-2 when values in ranges
This is the #tempTable2..I need to update 'String_To_Use' column so it would contain: 0000-1020, 1199-1210, 1260, 1299. #tempTable1 can help to build the logic
replace dsBranchPlant with name of your data set that your using to supply data parameter. And "All" condition is if all params are choosen instead of showing each one. Game this up as an expression and see where you stand.
iif(Parameters!BranchPlant.Count = CountRows("dsBranchPlant"),"ALL",Join(Parameters!BranchPlant.Label,","))

Convert text to date sql

I've seen a few posts on here and dotted around on the internet but I'm still struggling to implement my findings to get this to work.
I am currently trying to pull through a date field and run parameters on this field however everything I do fails and it still comes through as text or I experience an error.
Here is my current code:
SELECT CEL_SLT.ACCOUNT,
CEL_SLA.NAME,
CEL_SLT.STOCK_CODE,
**CEL_SLT.DATE**,
CEL_SLT.STOCK_QTY,
CEL_SLT.AMOUNT,
CEL_SLT.ORDER_NO
FROM Datafile.dbo.CEL_SLA CEL_SLA, Datafile.dbo.CEL_SLT CEL_SLT
WHERE CEL_SLA.ACCOUNT = CEL_SLT.ACCOUNT
AND ((CEL_SLT.STOCK_CODE Like 'F%' And CEL_SLT.STOCK_CODE Not Like 'FNX%')
AND (CEL_SLT.ACCOUNT=?)
I need the field CEL_SLT.DATE to come through as a date field.
I hope this makes sense and someone can help.
Assuming that your data is clean (in other words, the text data actually looks like a date), you can do it with either the CAST or CONVERT command.
SELECT CAST(CEL_slt.DATE as date)

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

Dynamic Date using Analysis Services in Report builder

Looking for help on this one. I'm working on a report in Report Builder that uses data from the Analysis Services cube and it is giving me a lot of problems when it come to any date/time data. I am trying to build a dynamic report that will allow the report to update depending on when it is viewed. I do this by setting parameters (#FromDateDate and #ToDateDate). Unfortunately MDX seems to hate dates which makes no sense to me.
My goal is to get data over a span of three months with the #ToDateDate being Today() and the #FromDateDate being 3 months in the past which I am able to achieve with this function (=DateAdd(DateInterval.Day,-90,Today()) ). However those don't go well with MDX.
My query looks like this:
SELECT
NON EMPTY
{[Measures].[Work Item Count]} ON COLUMNS
,NON EMPTY
{
[Date].[Year - Month - Date Hierarchy].[Date].ALLMEMBERS*
[Work Item].[System_State].[System_State].ALLMEMBERS*
[Work Item].[Microsoft_VSTS_Common_Severity].[Microsoft_VSTS_Common_Severity].ALLMEMBERS
}
DIMENSION PROPERTIES
MEMBER_CAPTION
,MEMBER_UNIQUE_NAME
ON ROWS
FROM
(
SELECT
StrToMember
(#FromDateDate
,CONSTRAINED
)
:
StrToMember
(#ToDateDate
,CONSTRAINED
) ON COLUMNS
FROM
(
SELECT
{[Work Item].[System_WorkItemType].&[Bug]} ON COLUMNS
FROM
(
SELECT
{
[Team Project].[Team Project Hierarchy].&[{6F43CBFD-2E98-4CA7-B428-0B732603517A}]
} ON COLUMNS
FROM [Work Item]
)
)
)
WHERE
(
[Team Project].[Team Project Hierarchy].&[{6F43CBFD-2E98-4CA7-B428-0B732603517A}]
,[Work Item].[System_WorkItemType].&[Bug]
)
CELL PROPERTIES
VALUE
,BACK_COLOR
,FORE_COLOR
,FORMATTED_VALUE
,FORMAT_STRING
,FONT_NAME
,FONT_SIZE
,FONT_FLAGS;
I was able to figure out how to essentially inject he appropriate format by adjusting my Parameter Values in the Dataset Properties to this -
="[Date].[Date].&["+format(Parameters!FromDateDate.Value,"yyyy-MM-ddThh:mm:ss")+"]"
My two parameters have default values of :
=DateAdd(DateInterval.Day,-90,Today()) and =Today()
When I run my report I get the following error:
The restrictions imposed by the CONSTRAINED flag in the STRTOMEMBER function were violated.
Now if I remove CONSTRAINED from the STRTOMEMBER function I get another error. I have also tried removing the entire STRTOMEMBER function and just using the parameters which I can get to work in Management Studio but not in Report builder. Please Help! I have attempted so many different ways and still no success. Let me know what additional information is needed.
Another thing -
If I remove the T in the date format of the Parameter Value in the Dataset Property to look like this:
="[Date].[Year - Month - Date Hierarchy].[Date].&["+format(Parameters!FromDateYearMonthDateHierarchy.Value,"yyyy-MM-dd hh:mm:ss")+"]"
I get the below error:
The '2017-06-08 12:00:00' string cannot be converted to the date type.
So here is the solution if anyone is interested. I've seen a ton of forum posts online with no one having a concrete answer so I can see this is a common problem - the workaround at this link is valid and does work:
Using Dynamic MDX in Reporting Services
My issue was the format of my "injected" date. When running the query generated by my #ToDateDate and #FromDateDate parameters...
(note: after changes I made my parameters are now
#FromDateYearMonthDateHierarchy and '#ToDateYearMonthDateHierarcy`
which you will notice in my Parameter Value function)
My Parameter Values appeared in the following format:
[Date].[Year - Month - Date Hierarchy].[Date].&[2010-12-31T00:00:00]
In order to fix the issue for me my "injection statement" had to look like this:
"[Date].[Year - Month - Date Hierarchy].[Date].&[" & Format(CDate(Parameters!FromDateYearMonthDateHierarchy.Value),"yyyy-MM-dd") & "T00:00:00]"
With the actual date formatting of "yyyy-MM-dd") & "T00:00:00]" so in the end the hours minutes and second was what was giving me the headache. The injection works perfectly but just need to pay attention to the Formatting of the date and time. I genuinely hope this helps someone!

Bit conversion not working in SSRS report

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.

Resources