求助!!

jwdream2008 2010-03-26 09:36:31
写个存储过程判断一个表是否存在,如果没有就创建表,如果有就做其他的操作。怎么写 ???
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO

create 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
begin

end

END

这样写,貌似有错啊!
...全文
154 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
jwdream2008 2010-03-27
感谢各位的捧场啊!
回复
SQL77 2010-03-26
[Quote=引用 8 楼 htl258 的回复:]
SQL code
create PROCEDURE [dbo].[GetDOCNO]
AS
BEGIN
if object_id('tempdb..#DOCNO') is null
BEGIN
create table #DOCNO(DocType varchar(20) --单据类型
,Describe varchar(50)……
[/Quote]
TONY哥UP
回复
htl258_Tony 2010-03-26
create PROCEDURE [dbo].[GetDOCNO]
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'
end

END
还真是不少问题
回复
东那个升 2010-03-26
[Quote=引用 6 楼 jwdream2008 的回复:]
引用 3 楼 ldslove 的回复:
create PROCEDURE [dbo].[GetDOCNO]()


除了这个括号错误外,还有其它问题啊!
[/Quote]

上面各位老大都写了
回复
jwdream2008 2010-03-26
[Quote=引用 3 楼 ldslove 的回复:]
create PROCEDURE [dbo].[GetDOCNO]()
[/Quote]

除了这个括号错误外,还有其它问题啊!
回复
htl258_Tony 2010-03-26
create PROCEDURE [dbo].[GetDOCNO]()
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'
end

END
回复
SQL77 2010-03-26
if object_id('#DOCNO') is null
对,这里也有问题只能是TEMPDB..#TB
回复
东那个升 2010-03-26
create PROCEDURE [dbo].[GetDOCNO]()
回复
htl258_Tony 2010-03-26
if object_id('tempdb..#DOCNO') is null 
回复
SQL77 2010-03-26
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO

create 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
begin

end

END
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2010-03-26 09:36
社区公告
暂无公告