即使在Parameter声明出错后,我仍在使用以下查询,可以在SQL Server上执行但在SSRS上出错,请帮帮我。
declare @Fromdate date = '1/1/2018' ,@Todate date ='12/31/2018' ,@Date nvarchar(10)
Begin
set @Date = left(convert(VARCHAR,@Fromdate,112),6)
while @Fromdate <= @Todate
Begin
SET @Fromdate = (select REPLACE
(LEFT(CONVERT(VARCHAR,DATEADD(MM,1,convert(date
,@Fromdate)),120),10),'-',''))
if @Fromdate <= @Todate
begin
SET @Date = left(convert(VARCHAR,@Fromdate,112),6)
select @Date as Date
END
END
END
答案 0 :(得分:0)
尝试将SSRS传递给单个结果集。也许以下方法会起作用。以下使用表变量插入日期,然后将其选择为结果集。
declare
@Fromdate date = '1/1/2018' ,
@Todate date ='12/31/2018' ,
@Date nvarchar(10)
Declare @tbl Table (dt nVarChar(10))
Begin
while @Fromdate <= @Todate
Begin
SET @Fromdate = (select REPLACE
(LEFT(CONVERT(VARCHAR,DATEADD(MM,1,convert(date
,@Fromdate)),120),10),'-',''))
if @Fromdate <= @Todate
begin
SET @Date = left(convert(VARCHAR,@Fromdate,112),6)
Insert Into @tbl Values (@Date)
END
END
END
Select * From @tbl
更新:清理了一下。我确认这可以用作SSRS数据集:
Declare @Fromdate date = '1/1/2018'
Declare @Todate date ='12/31/2018'
Declare @tbl Table (dt nVarChar(10))
Begin
while @Fromdate <= @Todate
Begin
SET @Fromdate = (select REPLACE
(LEFT(CONVERT(VARCHAR,DATEADD(MM,1,convert(date
,@Fromdate)),120),10),'-',''))
if @Fromdate <= @Todate
begin
Insert Into @tbl Values (left(convert(VARCHAR,@Fromdate,112),6))
END
END
END
Select * From @tbl
答案 1 :(得分:0)