我开始写这个SP只是为了发现它不起作用。如果我不必,我不想两次ping服务器。我基本上需要樱桃挑选已经存在托盘的部分(变量指定为参数),如果它们不存在,只需挑选顶部。问题是,我想将它作为记录集返回,所以我得到了下一个X数量的部分。我需要"预测"用托盘。
SET @test = (SELECT [SERIAL_NUMBER] FROM [ROBOTICS_OPTICS_MECHUAT].[dbo].[AOF_ORDER_OPTICS]
WHERE ([RACK] = @leftStack AND [TRAY] = @leftTray)
OR ([RACK] = @midStack AND [TRAY] = @midTray)
OR ([RACK] = @rightStack AND [TRAY] = @rightTray))
IF NULLIF(@test, '') IS NULL
BEGIN
SELECT TOP 6 [RACK], [TRAY], [POSITION] FROM [ROBOTICS_OPTICS_MECHUAT].[dbo].[AOF_ORDER_OPTICS]
WHERE ([RACK] = @leftStack AND [TRAY] = @leftTray)
OR ([RACK] = @midStack AND [TRAY] = @midTray)
OR ([RACK] = @rightStack AND [TRAY] = @rightTray)
END
ELSE
BEGIN
SELECT TOP 6 [RACK], [TRAY], [POSITION] FROM [ROBOTICS_OPTICS_MECHUAT].[dbo].[AOF_ORDER_OPTICS]
END
答案 0 :(得分:1)
您需要让SELECT测试为您的变量赋值,如下所示:
SELECT @test = [SERIAL_NUMBER] FROM [ROBOTICS_OPTICS_MECHUAT].[dbo].[AOF_ORDER_OPTICS]
WHERE ([RACK] = @leftStack AND [TRAY] = @leftTray)
OR ([RACK] = @midStack AND [TRAY] = @midTray)
OR ([RACK] = @rightStack AND [TRAY] = @rightTray)