在MS SQL SERVER报表生成器中声明问题

时间:2017-03-23 18:39:55

标签: sql sql-server sql-server-2008 reportbuilder

我遇到了一个不断出现错误信息的问题,其中表明"必须声明标量变量" @ station"。

另外,我正在设置"具体"站进入"单位"通过布尔但我不知道这是否是使用参数的正确方法" @ station"

如果有人能指出我正确的方向,我会非常感激。

    declare @Dbgn datetime,
    @Dend datetime;
set @Dbgn = @dateFrom + @ShiftStart;
set @Dend = @Dbgn + 1;

if @station = 1
begin
  -- set (Fields!unit.Value =(695, 696, 697 ,698, 651, 652, 653, 654, 655, 656, 657));
end
else
begin
  -- set (Fields!unit.Value =(51, 52, 221, 531, 532, 533, 534));
end
begin
SELECT  operator,
    unit,
    case
         when isNull(ScriptRate,0) > 0 and isNull(ItemRate,0) = 0 then 'Scripts'
         when isNull(ScriptRate,0) = 0 and isNull(ItemRate,0) > 0 then 'Items'
         when isNull(ScriptRate,0) > 0 and isNull(ItemRate,0) > 0 then '-X-'
         else '?'
    end  AS Type,
    SUM(ISNULL(numorders, 0))    AS totalorders,
    SUM(ISNULL(numscripts, 0))   AS totalscripts,
    SUM(ISNULL(numitems, 0))     AS totalitems,
    SUM(ISNULL(minuteslogon, 0)) AS totalminutes,
    case 
         when activityhour = 0 then 24
         else activityhour
    end as activityhour,
    sum( case
         when isNull(ScriptRate,0) > 0 and isNull(ItemRate,0) = 0 then ss.numscripts
         when isNull(ScriptRate,0) = 0 and isNull(ItemRate,0) > 0 then ss.NUMITEMS
         else 0
    end )     AS totalpvitems,
    avg( case
         when isNull(ScriptRate,0) > 0 and isNull(ItemRate,0) = 0 then unit.ScriptRate
         when isNull(ScriptRate,0) = 0 and isNull(ItemRate,0) > 0 then unit.ItemRate
         else 0
    end )     AS targetRate
FROM    mck_hvs.stationstats ss with( nolock ),
    mck_hvs.unit with( nolock )
WHERE   ss.unit = unit.unitno
    and activitytype > 1
    and ( createdate >= cast( @Dbgn as datetime) )
    and ( logofftime <= cast( @Dend as datetime) )

GROUP BY operator,
    unit,
    case
         when isNull(ScriptRate,0) > 0 and isNull(ItemRate,0) = 0 then 'Scripts'
         when isNull(ScriptRate,0) = 0 and isNull(ItemRate,0) > 0 then 'Items'
         when isNull(ScriptRate,0) > 0 and isNull(ItemRate,0) > 0 then '-X-'
         else '?'
    end,
    case 
         when activityhour = 0 then 24
         else activityhour
    end
ORDER BY operator asc,
    unit desc,
    activityhour
end

0 个答案:

没有答案