谁能告诉我为什么这会返回一个int类型?
ALTER PROCEDURE [dbo].[spTableExists] @TableName char(40), @Exists char(5) OUTPUT
AS
IF object_id(@TableName) is not null
select @Exists = 'true'
ELSE
select @Exists = 'false'
谁能告诉我为什么这会返回一个int类型?
ALTER PROCEDURE [dbo].[spTableExists] @TableName char(40), @Exists char(5) OUTPUT
AS
IF object_id(@TableName) is not null
select @Exists = 'true'
ELSE
select @Exists = 'false'
我认为这是因为@Exists 参数数据类型是“char(5)”。
当数据具有固定长度时,必须使用 Char。
尝试这个:
CREATE PROCEDURE [dbo].[spTableExists] @TableName varchar(40), @Exists varchar(5) OUTPUT
AS
SET @Exists = 'false'
IF object_id(@TableName) is not null
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(@TableName) AND type in (N'U'))
BEGIN
SET @Exists = 'true'
END
ELSE
SET @Exists = 'false'
SELECT @Exists
缺少一个set nocount on
语句,它返回一个行数。因为它不返回任何其他结果,所以它只是做一个赋值,这就是你得到的全部。