问题
I currently have a report with two parameters. Both those parameters have a datatype of "text". I am having an issue passing the desired value to these parameters from SQL because the variables that represent those parameters in SQL cannot be text due to variables not being able to be "text" datatypes in SQL now. The variables right now are "datetime" datatypes. I tried using some other text like datatype in SQL such as nvarchar, nchar, char, varchar etc. but none of those solved my problem. I am wondering if there is a way that I can get the desired data passed to SSRS without changing the parameter date type in SSRS to date/time?
Here is a snippet of the code I am working with:
DECLARE @CBFCycleStart as datetime
DECLARE @CBFCycleEnd as datetime
SET @CBFCycleStart =
(SELECT TOP 1 [CycleStartedOn]
FROM [IPEC_P_CIP_TKB_PREFLT]
WHERE [CycleComplete] = '1'
ORDER BY [CycleStartedOn] DESC)
SET @CBFCycleEnd =
(SELECT TOP 1 [CycleEndedOn] FROM
[IPEC_P_CIP_TKB_PREFLT]
WHERE [CycleComplete] = '1'
ORDER BY [CycleStartedOn] DESC)
回答1:
You can convert the datetime to String, like:
DECLARE @CBFCycleStart nvarchar(50);
SET CBFCycleStart=CONVERT(nvarchar(50), (SELECT TOP 1 [CycleStartedOn]
FROM [IPEC_P_CIP_TKB_PREFLT]
WHERE [CycleComplete] = '1'
ORDER BY [CycleStartedOn] DESC), 120);
回答2:
I believe you are trying to set report parameters from the result set of a stored procedure.
You are almost there, add one more line to your SP.
DECLARE @CBFCycleStart as datetime
DECLARE @CBFCycleEnd as datetime
SET @CBFCycleStart =
(SELECT TOP 1 [CycleStartedOn]
FROM [IPEC_P_CIP_TKB_PREFLT]
WHERE [CycleComplete] = '1'
ORDER BY [CycleStartedOn] DESC)
SET @CBFCycleEnd =
(SELECT TOP 1 [CycleEndedOn] FROM
[IPEC_P_CIP_TKB_PREFLT]
WHERE [CycleComplete] = '1'
ORDER BY [CycleStartedOn] DESC)
**select @CBFCycleStart as CBFCycleStart , @CBFCycleEnd as CBFCycleEnd**
name this dataset getStartAndEnd
This will give you a dataset with one row.
Now go to your parameters and set the values as defaults from this dataset getStartAndEnd
Additional Note:
I think you can rewrite your SP to this:
select CBFCycleStart = MAX([CycleStartedOn])
, CBFCycleEnd = MAX(CycleEndedOn)
FROM [IPEC_P_CIP_TKB_PREFLT]
WHERE [CycleComplete] = '1'
来源:https://stackoverflow.com/questions/56953807/ssrs-text-parameter-tied-to-sql-variable