MSSQL 判断临时表是否存在】的更多相关文章

方法一: if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#tempcitys') and type='U') drop table #tempcitys 注意tempdb后面是两个. 不是一个的 方法二: if object_id('tempdb..#tem') is not null begin print 'exists' end else begin print 'not exis…
原文来自:http://www.cnblogs.com/szfhquan/p/4229150.html 方法一: 1 if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#tempcitys') and type='U') 2 drop table #tempcitys 注意tempdb后面是两个. 不是一个的 方法二: if object_id('tempdb..#tem') is not…
MSSQL 判断一个时间段是否在另一个时间段内! 1 CREATE TABLE #B ( MeetingRoom int, BeginTime datetime, EndTime datetime ) insert into #B ,'2012-05-24 10:00:00','2012-05-24 16:00:00' DECLARE @BeignTime datetime --查询开始时间 DECLARE @EndTime datetime --查询结束时间 DECLARE @MeetingR…
MS SQL SERVER 2008 使用OBJECT_ID判断临时表是否存在 我们在写sql 脚本的时候经常会用到临时表,有时间也需要根据临时表是否存在做一些逻辑处理.还好sql server已经集成了一个Object_ID的函数,能够判断是否创建了临时表.使用挺方便的.   OBJECT_ID 参数: 'object_name' 要使用的对象.object_name 的数据类型为 varchar 或 nvarchar.如果 object_name 的数据类型为 varchar,则它将隐式 转…
IF OBJECT_ID('TEMPDB..#BCROSSREFERENCE ') IS NOT NULL DROP TABLE #BCROSSREFERENCE IF OBJECT_ID('TEMPDB..#SCVTMP_BCUSTOMER') IS NOT NULL DROP TABLE #SCVTMP_BCUSTOMER IF OBJECT_ID('TEMPDB..#PDS_CREATE_SCV_TEMP') IS NOT NULL DROP TABLE #PDS_CREATE_SCV_T…
执行语句 SELECT 'SELECT * FROM '+Name+'..SysObjects Where XType=''U'' and name=''tab_scartrim'' ORDER BY Name' FROM Master..SysDatabases ORDER BY Name 生成如下语句 SELECT * FROM ********************..SysObjects Where XType='U' and name='tab_scartrim' ORDER BY…
IF EXISTS(select * from tempdb..sysobjects where id=object_id('tempdb..#tb')) BEGIN DROP TABLE #tb END…
SET STATISTICS io ONSET STATISTICS time ONgo--========此处为sql代码段=============== select zxbh from t_yr03_zxxx where k_gh='0DF41D83-E0CE-4928-B838-76ACC84F1A4C' and sfct=1and exists (select k_zx from t_yr05_ctzx ctzx where ctzx.k_zx=t_yr03_zxxx.k_zxand…
declare @StartQuarter int declare @StartYear int declare @EndQuarter int declare @EndYear int declare @StartRange int, @EndRange int, @SYear int, @SQuarter int set @SYear=@StartYear set @SQuarter=@StartQuarter ),@SYear)+convert(varchar(),@SQuarter))…
1.临时表: 1.1)实例1 if(OBJECT_ID('tempdb..#a') IS NOT NULL) drop table #a; if(OBJECT_ID('tempdb..#b') IS NOT NULL) drop table #b; SELECT name into #a from syscolumns a with(nolock) where id=OBJECT_ID('NewsLetterSystem_Subscriber'); SELECT name into #b fro…