I have a nvarchar cell with some number as is : 12345678, and I would format it like this : 12-345-678. But I'm unable to find the right expression...
Should I do this in TSQL before inserting it in the report ?
I'm using SSRS 2008
You can do this in either T-SQL or an SSRS expression.
T-SQL:
declare #value nvarchar(8);
select #value = '12345678';
select formattedValue = left(#value, 2)
+ '-' + substring(#value, 3, 3)
+ '-' + right(#value, 3);
SSRS expression:
=Left(Fields!value.Value, 2)
& "-" & Mid(Fields!value.Value, 3, 3)
& "-" & Right(Fields!value.Value, 3)
This assumes a fixed length text.
It's really up to you which is better - I suppose one consideration would be to keep the formatting at the presentation layer, i.e. SSRS, so that's probably the way I would go. But nothing stopping you using either option.
Related
I'm using the standard version of SSRS 2016, so no access to data-driven subscriptions. I have a report subscription that is run daily utilizing a fixed StartDate parameter and the default value of an EndDate parameter that uses an expression to set its value to today's date.
I need for the subscribers to reuse the links after the report schedule date has past, but the link in the subscription email only includes the first parameter value, so the EndDate always uses today's date, not the date the subscription email was generated.
I'm wanting to retain the parameter values of the day the report was run. Is there a way to force the inclusion of the parameter values in the email subscription link?
Any ideas?
Thanks in advance.
You could create a SQL Server job to send a custom email with your report link.
DECLARE #report_url NVARCHAR(500) = ''; --update the report url here
DECLARE #email_body NVARCHAR(MAX) = NULL;
BEGIN
SET #email_body = '<html><body>Hi,
<br><br>
You can access the report in the link below.
<br>
Your Report
<br>
<br>
</body></html>';
EXEC [msdb].[dbo].[sp_send_dbmail]
#profile_name = 'YourProfileNameHere',
#body = #email_body,
#body_format = 'HTML',
#recipients = 'first.last#yourcompany.com; first.last#yourcompany.com',
#blind_copy_recipients = 'first.last#yourcompany.com',
#subject = 'Report Email Subject',
#query_result_no_padding = 1;
WAITFOR DELAY '00:00:02';
END;
You can build the report url in the footer of the report with parameters.
=Globals!ReportServerUrl + "/ReportServer?"
+ Replace(Globals!ReportFolder, " ", "+") + "%2f"
+ Replace(Globals!ReportName, " ", "+")
+ "&ReportFolder=" + Join(Parameters!ReportFolder.Value, "&ReportFolder=")
+ "&SearchType=" + Join(Parameters!SearchType.Value, "&SearchType=")
+ IIf(IsNothing(Parameters!SearchFor.Value), "&SearchFor:IsNull=True", "&SearchFor=" + Parameters!SearchFor.Value)
+ IIf(IsNothing(Parameters!CreatedDateFrom.Value), "&CreatedDateFrom:IsNull=True", "&CreatedDateFrom=" + Format(Parameters!CreatedDateFrom.Value, Variables!FormatDate.Value))
+ IIf(IsNothing(Parameters!CreatedDateTo.Value), "&CreatedDateTo:IsNull=True", "&CreatedDateTo=" + Format(Parameters!CreatedDateTo.Value, Variables!FormatDate.Value))
+ IIf(IsNothing(Parameters!ModifiedDateFrom.Value), "&ModifiedDate:IsNull=True", "&ModifiedDateFrom=" + Format(Parameters!ModifiedDateFrom.Value, Variables!FormatDate.Value))
+ IIf(IsNothing(Parameters!ModifiedDateTo.Value), "&ModifiedDateTo:IsNull=True", "&ModifiedDateTo=" + Format(Parameters!ModifiedDateTo.Value, Variables!FormatDate.Value))
+ "&CreatedBy=" + Join(Parameters!CreatedBy.Value, "&CreatedBy=")
+ "&ModifiedBy=" + Join(Parameters!ModifiedBy.Value, "&ModifiedBy=")
+ "&ShowSql=" + CStr(Parameters!ShowSql.Value)
To use Null as a parameter value use: [Parameter Name]:IsNull=True
To use multi value parameters, you must use the Join function
To use boolean values, you must change it to a string e.g. CStr or .ToString()
Name
Description
rs:Format
Rendering modes you can pass are HTML3.2, HTML4.0, MHTML, IMAGE, EXCEL, WORD, CSV, PDF, XML, defaults to HTML4.0
rc:Zoom
Specified in percentages, supports Page%20Width and Whole%20Page, defaults to 100%
rc:Toolbar
True/False, used to show/hide the toolbar, defaults to true
rc:Parameters
True/False/Collapsed, used to show/hide/collapse the parameters in the toolbar, defaults to true
rc:DocMap
True/False, used to show/hide document map, defaults to true (not shown unless report has document map)
rc:Section
Specifies default page number to display, defaults to 1
rc:BookMarkID
Jumps to a specific bookmark in a report
rc:FindString
Provides search criteria to the report and finds the first instance of the string specified
I am trying to pass a hyperlink in SSRS to open a new SSRS report (in pdf) from a text box. It is currently set up and works passing a single parameter :
="http://servername/ReportServer_REPORTS16/Pages/ReportViewer.aspx?%2fdummy%2fDocuments%2fCertificate+of+Insurance+Issued&rs:Command=Render&PolicyNo="
& Parameters!PolicyNo.Value &"&rs:Format=PDF"
However when I add in the second parameter :
="http://servername/ReportServer_REPORTS16/Pages/ReportViewer.aspx?%2fdummy%2fDocuments%2fCertificate+of+Insurance+Issued&rs:Command=Render&PolicyNo="
& Parameters!PolicyNo.Value &"&
Entitled="&Parameters!Entitled.Value &"&rs:Format=PDF"
I get an error message :
The ActionInfo.Action.Hyperlink expression for the text box
‘Textbox48’ contains an error: [BC30277] Type character '&' does not
match declared data type 'Object'.
I've gone through every similar error I've found on google but cant work out where im going wrong.
You need to convert all your values to strings then use the + operator....
Here'a an exmaple from one of my reports that does the same thing.
=IIF(Fields!PackSizeDesc.Value = Nothing, Nothing,
"http://MyServername/ReportServer?/Brand+Value/_sub+SKU+Price+Details"
+ "&CountryID=" + cStr(Fields!CountryID.Value)
+ "&CategoryID=" + cStr(Fields!CategoryID.Value)
+ "&RecordedPeriodID=" + cStr(Parameters!PeriodID.Value)
+ "&TMB=" + cStr(Fields!TrademarkBrandID.Value)
+ "&PriceStage=" + cStr(IIF(Fields!IsActualprice.Value = 1, 10, 11))
+ "&pm=" + cStr(Fields!PackMaterialID.Value)
+ "&pt=" + cStr(Fields!PackTypeID.Value)
+ "&ps=" + cStr(Fields!PackSizeID.Value)
+ "&psu=" + cStr(Fields!PackSizeUnitID.Value)
+ "&upp=" + cStr(Fields!UnitsPerPack.Value)
+ "&rc:Parameters=Collapsed")
Note: The first line just disables the link if there is now value in a particular column. This does not render to PDF but that's not part of your issue.
I'm trying to use conditional formatting in SQL Server Reporting Services to change the colour of a row if a value is the same as today's date or not. The column contains the date in the format 13/07/2018. I have also set the field to be in date format (31/01/2000) within place-holder properties.
My expression however is not working
=switch(DateDiff("d", Fields!LastSuccessfulBackupTime00.Value,Format(Now(),"dd/MM/yyyy")) = 0, "Green",DateDiff("d", Fields!LastSuccessfulBackupTime00.Value,Format(Now(), "dd/MM/yyyy")) = 1, "Yellow",DateDiff("d", Fields!LastSuccessfulBackupTime00.Value,Format(Now(), "dd/MM/yyyy")) >= 2, "Red")
The exception that is being thrown is
Argument matching parameter 'DayOfWeek' narrows from 'String' to 'Mcrosoft.VisualBasic.FirstDayOfWeek'
Which is strange because I'm just doing simple datediff calculation to count the number of days between two dates.
Can anyone suggest how to fix this ? Google just says to turn off strict compilation something which I can't find in SQLRS
Try the expression below (expression 1)
=switch(
DateDiff("d", Cdate(Fields!LastSuccessfulBackupTime00.Value),Today()) = 0, "Green"
,DateDiff("d", Cdate(Fields!LastSuccessfulBackupTime00.Value),Today()) = 1, "Yellow"
,DateDiff("d", Cdate(Fields!LastSuccessfulBackupTime00.Value), Today()) >= 2, "Red"
)
Also because Cdate is regional setting dependant you could use Split to create a valid date format for datediff (expression2)
=switch(
DateDiff("d", Fields!LastSuccessfulBackupTime00.Value.Split("/")(2) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(1) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(0),Today()) = 0, "Green"
,DateDiff("d", Fields!LastSuccessfulBackupTime00.Value.Split("/")(2) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(1) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(0),Today()) = 1, "Yellow"
,DateDiff("d", Fields!LastSuccessfulBackupTime00.Value.Split("/")(2) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(1) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(0),Today()) >= 2, "Red"
)
I am having an issue with a divide by zero error that I have half way worked through.
Basically I need (EstimatedValuePlanned - EAC) / EstimatedValuePlanned
I have the following, however I am still getting #Error on some:
= IIF (Fields!EstimatedValuePlanned.Value = 0 , 0,
Fields!EstimatedValuePlanned.Value - Fields!EAC.Value)
/
SUM(Fields!EstimatedValuePlanned.Value)
I have changed the code around several times but I still either get Error or NaN
Thank you
IIF will always evaluate both parts of the function, so when SUM(Fields!EstimatedValuePlanned.Value) is zero you will get the error even though that's not what will be returned.
Try using a SWITCH statement. SWITCH stops once an expression returns True.
Something like this
= SWITCH(
SUM(Fields!EstimatedValuePlanned.Value) = 0 , 0,
True, (Fields!EstimatedValuePlanned.Value - Fields!EAC.Value) / SUM(Fields!EstimatedValuePlanned.Value)
)
The True expression simply acts like an else
UPDATE WITH SAMPLE
I created a new report added a dataset and set the dataset query to be the following (just to generate some dummy data).
DECLARE #t TABLE (EVP float, EAC float)
INSERT INTO #t VALUES
(1,2),
(2,3),
(5,4),
(0,2),
(1,0),
(0,0)
SELECT * FROM #t
I then added a table, set the first to columns to be EVP and EAC respectively and set the 3rd column to an expression as follows.
=SWITCH (
Fields!EVP.Value = 0, 0
, True, (Fields!EVP.Value - Fields!EAC.Value) / Fields!EVP.Value
)
The report design looks like this.
And when it's run this is the result....
Try replicating the above steps and see if you can get it to work like this first then review difference to your report.
I got it to work with:
=IIF (Fields!EstimatedValuePlanned.Value = 0 , 0,
Fields!EstimatedValuePlanned.Value - Fields!EAC.Value)
/
IIF(Fields!EstimatedValuePlanned.Value =
0,1,Fields!EstimatedValuePlanned.Value)
Thank you both
I have the following error which I can't understand from my expression.
=IIF(IsNothing(Fields!month.Value),"6mr",LEFT(Format(DateValue(MonthName(Right(Fields!month.Value, 2))
+ "," +
Left(Fields!month.Value,4)), "Y"),3) + " '" + RIGHT(Format(DateValue(MonthName(Right(Fields!month.Value, 2))
+ "," +
Left(Fields!month.Value,4)), "Y"),2))
This works perfectly without the IsNothing element.
I have tested the IsNothing element and that works in the following case:
=IIF(IsNothing(Fields!month.Value),"6mr",0).
Help to correct much appreciated.
You are experiencing this "issue" because Reporting Services evaluates both sides of the Iif.
This is not really an issue, it is by design, see this technet article for more details:
SSRS - IIF function evaluates both True & False
Yes , By design the SSRS evaluates both True & False statements even
though the condition is not satisfied and through error if something
is not right.
Now, to get your expression working, you have to consider that Fields!month.Value could be nothing even in the false part of your expression.
So in your expression, you could just replace
Fields!month.Value
by
Iif(IsNothing(Fields!month.Value), "1", Fields!month.Value)
Here is an expression with this fix:
=Iif(IsNothing(Fields!month.Value),"6mr",Left(Format(DateValue(MonthName(Right(Iif(IsNothing(Fields!month.Value), "1", Fields!month.Value), 2))
+ "," +
Left(Iif(IsNothing(Fields!month.Value), "1", Fields!month.Value),4)), "Y"),3) + " '" + Right(Format(DateValue(MonthName(Right(Iif(IsNothing(Fields!month.Value), "1", Fields!month.Value), 2))
+ "," +
Left(Iif(IsNothing(Fields!month.Value), "1", Fields!month.Value),4)), "Y"),2))
You could also create a custom function or use a variable if you want to reduce the expression length.