简体   繁体   中英

SSRS Parameter doesn't display even though the query works

I have a query to fill a report parameter:

select distinct [Source No_] from _report_sales_master
where [Industry] = @Industries
and [posting date] >= dateadd(year,datediff(year,'01/06/2000',@year)-1,'01/06/2000') 
and  [posting date] < dateadd(year,datediff(year,'01/06/2000',@year),'01/06/2000')
order by [Source No_]

The query results in a list that I use to fill a multi-value report parameter.

When I run the query, it generates the right results.

When I run the report, the "Source No_" parameter stays empty, no matter which @year or @industries i choose

When I remove the "posting date" clauses from the query, the parameter list populates and works properly.

What am I missing?

Try putting your hard-coded dates (string-literals) in the format 'yyyy-mm-dd' . I've found when putting dates in the format you have, ie dd/mm/yyyy or mm/dd/yyyy, that SSRS can mix up which is the month and which is the date.

I've played around with various settings at both the db and SSRS level for date localisation and have found that any date strings in your format can cause issues (I don't know the specific cause).

As you are using strings-literals there is an implicit conversion carried out to resolve it to one of the following: time, date, smalldatetime, datetime, datetime2 , or datetimeoffset value.

Another way to prevent date malformations is replace your string literal with an explicit cast, for example:

  • CONVERT(datetime, '2012-06-01', 101) Assumes month = June
  • CONVERT(datetime, '2012-01-06', 101) Assumes month = January

The only other thing I can think of to check is that the parameter in the report is set to the correct data type for the column [Source No_] .

Put this in your database and play around:

DECLARE @year DATETIME
SELECT @year = TypeDateTimeInputHere
SELECT dateadd(year,datediff(year,'01/06/2000',@year)-1,'01/06/2000') [GT posting date]
,dateadd(year,datediff(year,'01/06/2000',@year),'01/06/2000') [LT posting date]

I cannot tell what you're trying to do with your greater than or equal to (GT) and your less than (LT) logic, but I don't think it does what you're expecting it or wanting it to. Every time I test it, I get the same results unless I force the [posting date] to be some date less than 1/6/2000.

obviously, replace "TypeDateTimeInputHere" with sample values that you know are or are expecting to be in [posting date].

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