在 MS SQL SERVER Report Builder 中声明问题

问题描述 投票:0回答:1

我遇到了不断出现错误消息的问题,该消息指出“必须声明标量变量“@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
sql sql-server sql-server-2008 reportbuilder
1个回答
0
投票

您的代码的问题在于您的代码未声明而是使用了变量“@station”。您需要声明@station

DECLARE @Dbgn datetime,
    @Dend datetime,
    @station int; -- Declare @station as an integer, assuming it's an 
integer parameter.

-- Set your other variables and parameters
SET @Dbgn = @dateFrom + @ShiftStart;
SET @Dend = @Dbgn + 1;

-- The rest of your code follows
if @station = 1
begin
  -- Your logic for station = 1
end
else
begin
  -- Your logic for station not equal to 1
end

 -- The SELECT statement and the rest of your code follows
© www.soinside.com 2019 - 2024. All rights reserved.