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
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
-- 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
IF OBJECT_ID('@tableName','U') IS NOT NULL
@s_exit = 0
ELSE @s_exit = 1
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
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了。
-- 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
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
@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
-- 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
那我在C#或者其它语言中调用这个存储过程,怎么获取这个输出参数@s_exist呢
谢谢
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)
{
.......
}
参考
-- 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
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’附近有语法错误
应该怎么改呢