注册 登录
编程论坛 SQL Server论坛

关于定义布尔值的变量

梦幻倩影 发布于 2016-09-23 09:37, 2138 次点击
declare @ss bit
set @ss= exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[cgjggz]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

为何上面在查询分析器中执行会出错首乌,而下面的语句则不会
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[cgjggz]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
select * from cgjggz

[此贴子已经被作者于2016-9-23 09:39编辑过]

2 回复
#2
mywisdom882016-09-23 17:42
以下是引用梦幻倩影在2016-9-23 09:37:34的发言:

declare @ss bit
set @ss= exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[cgjggz]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

为何上面在查询分析器中执行会出错首乌,而下面的语句则不会
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[cgjggz]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
select * from cgjggz

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[cgjggz]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
set @ss=1
else
set @ss=0
#3
梦幻倩影2016-09-23 18:27
为何不能直接取值?
1