创建存储过程时如何解决无效的列名错误?

时间:2019-11-14 10:21:14

标签: stored-procedures sql-server-2012

我在存储过程下面编写了代码,但得到了以下错误:

  

信息207,级别16,状态1,过程sp_GetAvailableSensor,第7行

     

无效的列名称“ SuctionWater1”。消息207,第16级,状态1,

     

过程sp_GetAvailableSensor,第8行无效的列名

     

“ SuctionWater2”。消息207,级别16,状态1,程序

     

sp_GetAvailableSensor,第11行无效的列名'SuctionPresure1'。

     

第207条消息,状态16,状态1,过程sp_GetAvailableSensor,第12行

     

无效的列名称“ SuctionPresure2”。

    USE [SpmsTwoSuctionOneThrust]
GO


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_GetAvailableSensor]
AS
BEGIN

    SELECT TOP 1 [Id],
           [PowerControl],
           [SuctionWater1],
           [SuctionWater2],
           [InundationWater],
           [EvacuationWater],
           [SuctionPresure1],
           [SuctionPresure2],
           [ThrustPressure]
    FROM   [SPMS].[dbo].[AvailableSensor]
END

enter image description here

1 个答案:

答案 0 :(得分:0)

您要从SPMS的另一个数据库中选择表:

FROM   [SPMS].[dbo].[AvailableSensor]

虽然存储过程和表模式在SpmsTwoSuctionOneThrust中:

USE [SpmsTwoSuctionOneThrust]

两个数据库之间的表架构可能不同。