数据集是这样的: SELECT ${if(type='date'," CONVERT(varchar(100),a.BillDate,20)) as riqi ,","")} ${if(type='month', " CONVERT(varchar(7),a.BillDate,20)) as riqi, ","")} ${if(type='year', " CONVERT(varchar(4),a.BillDate,20)) as riqi, ","")} a.ShopID 门店ID, b.BrandName 品牌, b.HotelName 门店, sum(a.Amount) 实际营收, c.[Value] 计划营收 FROM [dbo].[DIM_POS_Shop] b LEFT JOIN [dbo].[FACT_POS_Bill] a ON a.ShopID = b.ShopID LEFT JOIN [dbo].[FACT_Target_Day] c ON c.ShopID = b.HotelID where c.Items = '营收(万元)' ${if(type='date'," and CONVERT(varchar(100),a.BillDate,20) >= '" + 开始日期 + "' and CONVERT(varchar(100),a.BillDate,20)<='" + 结束日期 + "'", "")} ${if(type='month', " and cast(month(CONVERT(varchar(100),a.BillDate,20)) as int) = "+ 月 + " and year(CONVERT(varchar(100),a.BillDate,20)) = '" + 年+"'", "")} ${if(type='year', " and year(CONVERT(varchar(100),a.BillDate,20)) = '" + 年+"'", "")} ${if(len(品牌)==0,"","and b.BrandName in ('"+品牌+"')")} ${if(len(门店)==0,"","and b.HotelName in ('"+门店+"')")} GROUP BY a.ShopID, ${if(type='date'," CONVERT(varchar(100),a.BillDate,20)), ","")} ${if(type='month', " CONVERT(varchar(7),a.BillDate,20)), ","")} ${if(type='year', " CONVERT(varchar(4),a.BillDate,20)), ","")} b.BrandName, b.HotelName, c.[Value] 给开始时间,结束时间,年份默认数据预览时成功的 给TYPE参数默认值时,就开始报错: 给参数品牌默认值时,预览也是成功的: 参数的写法有问题吗? |