写个存储过程判断一个表是否存在,如果没有就创建表,如果有就做其他的操作。怎么写 ???
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GOcreate PROCEDURE [dbo].[GetDOCNO]()
AS
BEGIN
if object_id('#DOCNO') is null
BEGIN
create table #DOCNO(DocType varchar(20) --单据类型
,Describe varchar(50) --单据描述
,DocPrefix varchar(8) --单据前缀
,LastDate smalldatetime --单据操作时间
,CurDocValue int) --单据当前号
insert into #DOCNO
select 'Bill','对账单','21','2010-3-27 0:00:00','1' union all
select 'Sale','销售单','22','2010-3-27 0:00:00','1' union all
select 'Receipt','进货单','23','2010-3-27 0:00:00','1'
End
else
beginendEND这样写,貌似有错啊!
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GOcreate PROCEDURE [dbo].[GetDOCNO]()
AS
BEGIN
if object_id('#DOCNO') is null
BEGIN
create table #DOCNO(DocType varchar(20) --单据类型
,Describe varchar(50) --单据描述
,DocPrefix varchar(8) --单据前缀
,LastDate smalldatetime --单据操作时间
,CurDocValue int) --单据当前号
insert into #DOCNO
select 'Bill','对账单','21','2010-3-27 0:00:00','1' union all
select 'Sale','销售单','22','2010-3-27 0:00:00','1' union all
select 'Receipt','进货单','23','2010-3-27 0:00:00','1'
End
else
beginendEND这样写,貌似有错啊!
SET QUOTED_IDENTIFIER ON
GOcreate PROCEDURE [dbo].[GetDOCNO]()
AS
BEGIN
if object_id('#DOCNO') is null
BEGIN
create table #DOCNO(DocType varchar(20) --单据类型
,Describe varchar(50) --单据描述
,DocPrefix varchar(8) --单据前缀
,LastDate smalldatetime --单据操作时间
,CurDocValue int) --单据当前号
insert into #DOCNO
select 'Bill','对账单','21','2010-3-27 0:00:00','1' union all
'Sale','销售单','22','2010-3-27 0:00:00','1' union all
'Receipt','进货单','23','2010-3-27 0:00:00','1'
End
else
beginendEND
对,这里也有问题只能是TEMPDB..#TB
AS
BEGIN
if object_id('tempdb..#DOCNO') is null
BEGIN
create table #DOCNO(DocType varchar(20) --单据类型
,Describe varchar(50) --单据描述
,DocPrefix varchar(8) --单据前缀
,LastDate smalldatetime --单据操作时间
,CurDocValue int) --单据当前号
insert into #DOCNO
select 'Bill','对账单','21','2010-3-27 0:00:00','1' union all
select 'Sale','销售单','22','2010-3-27 0:00:00','1' union all
select 'Receipt','进货单','23','2010-3-27 0:00:00','1'
End
else
begin
truncate table #DOCNO
insert into #DOCNO
select 'Bill','对账单','21','2010-3-27 0:00:00','1' union all
select 'Sale','销售单','22','2010-3-27 0:00:00','1' union all
select 'Receipt','进货单','23','2010-3-27 0:00:00','1'
endEND
AS
BEGIN
if object_id('tempdb..#DOCNO') is null
BEGIN
create table #DOCNO(DocType varchar(20) --单据类型
,Describe varchar(50) --单据描述
,DocPrefix varchar(8) --单据前缀
,LastDate smalldatetime --单据操作时间
,CurDocValue int) --单据当前号
insert into #DOCNO
select 'Bill','对账单','21','2010-3-27 0:00:00','1' union all
select 'Sale','销售单','22','2010-3-27 0:00:00','1' union all
select 'Receipt','进货单','23','2010-3-27 0:00:00','1'
End
else
begin
truncate table #DOCNO
insert into #DOCNO
select 'Bill','对账单','21','2010-3-27 0:00:00','1' union all
select 'Sale','销售单','22','2010-3-27 0:00:00','1' union all
select 'Receipt','进货单','23','2010-3-27 0:00:00','1'
endEND还真是不少问题