简体   繁体   中英

SSRS 2017: Want to set a parameter to a default of NULL in a shared dateaset

the problem

I have a problem with a SSRS 2017 shared dataset.

This dataset is calling a stored procedure. One of the SP's parameters is of type DateTime . Within the dataset's parameters dialog I've set the default to (Null) . But this seems to be ignored...

With paginated reports everything works fine. The defined report parameters (or built-in parameters) can be used to pass valid values.

But when I try to use this dataset within a mobile report I get an error. I cannot even add the dataset! After quite some search I found, that the SP was called with a blank instead of NULL ( Pofiler tells me : ,@ClientTime=N'' ), hence the type conversion to DateTime failed.

I do not want to change this parameter to a string type, because this report will run in various environments. The correct date getting into the stored proc if taken as string is really awful: Nov 14 2017 3:35PM (culture and language dependant!) I do not want to rely on any conversion from string!

the question

How can I force a SSRS shared dataset to use a real NULL for a parameter?

Are you hosting this dataset in SharePoint? If so, are you sure the default value is actually set on the SharePoint saved version? I've always observed, that while you can set the value to null in your report designer, when it saves to SharePoint, the null default is lost. Simply, edit the dataset parameters from the SharePoint interface and select Null for the appropriate parameter after you have saved it. Although I haven't profiled parameters in a long timer, I often do a "@param IS NULL" test within my SQL and have never had issues.

Note that you don't have to do this each time you edit the dataset/report in the future, just on the initial save.

Well, I found a solution... Not really a solution to the problem, but it seems to help me out:

DECLARE @blank VARCHAR(1)='';
SELECT CAST(@blank AS DATETIME) AS toDateTime
      ,CAST(@blank AS DATETIME2) AS toDateTime2
      ,CAST(@blank AS TIME) AS toTime
      ,CAST(@blank AS DATE) AS toDate
      ,CAST(@blank AS BIT) AS toBit
      ,CAST(@blank AS INT) AS toInt
      ,CAST(@blank AS FLOAT) AS toFloat

the result

toDateTime          toDateTime2         toTime      toDate      toBit toInt toFloat
1900-01-01 00:00:00 1900-01-01 00:00:00 00:00:00    1900-01-01  0     0     0

The reason for the error on adding the dataset to a mobile report did not come from the DATETIME-conversion of a blank string but from a deeper place within my T-SQL-code, where I caculated a time difference and did not expect a value of 1900-01-01 . The error message is very large, half of the screen is covered with text, but there's no real hint about the reason...

But this throws an error, hence I'll avoid data types not converting from a blank natively:

SELECT CAST(@blank AS decimal(10,4)) AS toDecimal 

Msg 8114, Level 16, State 5, Line 10
Error converting data type varchar to numeric.

That means: I have to take the value 1900-01-01 as NULL . Still it is rather silly, that SSRS allows parameters with a default of NULL but to send a blank in the background.

If there are other solutions which lead to a real NULL I'd still be happy to read them!

UPDATE: Fun fact

The profiler tells me, that a paginated report passes a parameter set to (Null) as a blank (as shown in the question). But with a mobile Report the (Null) is passed over as ,@DateTimeFrom=N'Nothing' . The default value must be set to an empty value, which is taken as blank...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM