开发者

SSRS error: Conversion from string "string;#NA" to type 'Date' is not valid

开发者 https://www.devze.com 2023-03-29 16:33 出处:网络
My datasource is XML (sharepoint list). I basically want to show the date formatted if t开发者_如何学JAVAhe value in the field is a date and if not then show \"NA\". For some reason, even when the dat

My datasource is XML (sharepoint list). I basically want to show the date formatted if t开发者_如何学JAVAhe value in the field is a date and if not then show "NA". For some reason, even when the data is a a string it is still trying to convert it to a date somewhere. Here is my code..

=IIF
(
ISDATE(replace(First(Fields!ows_Manufacturing_Date.Value, "DataSet1"),"datetime;#","")),
formatdatetime(replace(First(Fields!ows_Manufacturing_Date.Value, "DataSet1"),"datetime;#",""),2),
replace(First(Fields!ows_Manufacturing_Date.Value, "DataSet1"),"string;#","")
)


The problem is that the IIF statement in SSRS doesn't short circuit, it always evaluates both conditions, so even if the field is not a date, it still tries to do the formatdatetime function.

(See this: SSRS iif function question)

Instead of the IIF function, try using the SWITCH function instead:

=SWITCH(First(Fields!ows_Manufacturing_Date.Value, "DataSet1")="string;#NA",
"NA",
First(Fields!ows_Manufacturing_Date.Value, "DataSet1")<>"string;#NA",
formatdatetime(replace(First(Fields!ows_Manufacturing_Date.Value, "DataSet1"),"datetime;#",""),2))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号