SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE up_inquireTableExist 
-- Add the parameters for the stored procedure here
    @tableName char(6),
@s_exist bit output
AS
    IF OBJECT_ID('@tableName','U') IS NOT NULL 
     @s_exit = 0
    ELSE @s_exit = 1
GO

解决方案 »

  1.   

    CREATE PROCEDURE up_inquireTableExist 
    -- Add the parameters for the stored procedure here 
        @tableName char(6), 
    @s_exist bit output 
    AS 
        IF OBJECT_ID('@tableName','U') IS NOT NULL 
        Set @s_exit = 0  -- 这里
        ELSE
        Set @s_exit = 1 
    GO 
      

  2.   


    IF OBJECT_ID('@tableName','U') IS NOT NULL 
        @s_exit = 0 
        ELSE @s_exit = 1 
      

  3.   

    SET ANSI_NULLS ON 
    GO 
    SET QUOTED_IDENTIFIER ON 
    GO 
    CREATE PROCEDURE up_inquireTableExist 
    -- Add the parameters for the stored procedure here 
        @tableName char(6), 
    @s_exist bit output 
    AS 
        IF OBJECT_ID('@tableName','U') IS NOT NULL 
        Set @s_exist = 0 
        ELSE
    Set @s_exist = 1 
    GO 
      

  4.   

    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE PROCEDURE up_inquireTableExist
    -- Add the parameters for the stored procedure here
        @tableName char(6),
    @s_exist bit output
    AS
        IF OBJECT_ID('@tableName','U') IS NOT NULL
        SET @s_exit = 0
        ELSE 
          SET @s_exit = 1
    GO 楼主忘了SET了。
      

  5.   

    CREATE PROCEDURE up_inquireTableExist 
    -- Add the parameters for the stored procedure here 
        @tableName char(6), 
    @s_exist bit output 
    AS 
        IF exists ( select 1 from sys.tables where name=@tableName
          set @s_exit = 0 
        ELSE 
          set @s_exit = 1 
    GO 
      

  6.   

    表名也不对。如果动态的,建议采用动态语句。
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE PROCEDURE up_inquireTableExist
    -- Add the parameters for the stored procedure here
        @tableName char(6),
    @s_exist bit output
    AS
        declare @sql varchar(1000)
        SET @sql='
        IF OBJECT_ID('''+@tableName+''',''U'') IS NOT NULL
        SET @s_exit = 0
        ELSE 
           SET @s_exit = 1'
    print @sql
    exec(@sql)
    GO 
      

  7.   

    alter PROCEDURE dbo.up_inquireTableExist
    @tableName char(6),
    @s_exist bit output
    AS
    begin
    IF OBJECT_ID('@tableName','U') IS NOT NULL
     select @s_exist =0
    ELSE  select @s_exist =1
    select @S_exist
    end
      

  8.   

    CREATE PROCEDURE up_inquireTableExist 
    -- Add the parameters for the stored procedure here 
    @tableName char(6), 
    @s_exist bit output 
    AS 
        IF OBJECT_ID(@tableName,'U') IS NOT NULL  --表名变量不用单引号
    set @s_exist = 0       --缺少set
        ELSE 
    set @s_exist = 1 
    GO 
      

  9.   

    这个问题解决了
    那我在C#或者其它语言中调用这个存储过程,怎么获取这个输出参数@s_exist呢
    谢谢
      

  10.   


    cm.Parameters.AddWithValue("@s_exist", 0);
    cm.Parameters["@s_exist"].DbType = DbType.Bit;
    cm.Parameters["@s_exist"].Direction = ParameterDirection.Output;
    cm.ExecuteNonQuery();if (int.Parse(cm.Parameters["@BudgetError"].Value.ToString()) == 1)
    {
    .......
    }
    参考
      

  11.   

    采用8楼的代码出现了错误:必须声明标量@s_exist
      

  12.   

    CREATE PROCEDURE up_inquireTableExist 
    -- Add the parameters for the stored procedure here 
        @tableName char(6), 
    @s_exist bit output 
    AS 
        IF exists ( select 1 from sys.tables where name=@tableName
          set @s_exit = 0 
        ELSE 
          set @s_exit = 1 
    GO 
      

  13.   

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    goALTER PROCEDURE [dbo].[up_inquireTableExist] 
    -- Add the parameters for the stored procedure here
        @tableName char(6),
    @s_exist int output
    AS
       --下面用动态SQL语句实现
       declare @sql varchar(1000)
       Set @sql = 'IF OBJECT_ID( ' + @tableName + ','U') IS NOT NULL
       Set @s_exist = 1
       ELSE
       Set @s_exist = 0'
       exec(@sql)我改成上述动态语句,结果出现错误:‘U’附近有语法错误
    应该怎么改呢