***写存储过程能用一些if..else的判断吗?***

xuege 2003-05-13 02:05:11
我想这样:
CREATE PROCEDURE zzz(@courseNo char(15))
AS
if @courseNo is null then
begin
select *
from course
end
else
begin
select *
from course
where course.courseNo=@courseNo
end
GO
“检查语法”总说在then和else有错误,是怎么回事?谢谢指点!!!
...全文
49 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
crycat 2003-05-13
好像是基本的语法题呢
怎么这么多人回答
回复
firetoucher 2003-05-13
up
不要then
CREATE PROCEDURE zzz(@courseNo char(15))
AS
if @courseNo is null
begin
select *
from course
end
else
begin
select *
from course
where course.courseNo=@courseNo
end
GO
回复
wuqiuzhi 2003-05-13
在sql server里面,判断使用的if。。。else
不是if。。。then。。。。else
故上面应该去掉then
回复
happydreamer 2003-05-13
CREATE PROCEDURE zzz(@courseNo char(15))
AS

IF @courseNo is null
BEGING
SELECT * FROM course
END
ELSE
BEGIN
SELECT * FROM course WHREE courseNo=@courseNo
END

GO
回复
mjhnet 2003-05-13
不需要then,去掉即可


CREATE PROCEDURE zzz(@courseNo char(15))
AS
if @courseNo is null
begin
select *
from course
end
else
begin
select *
from course
where course.courseNo=@courseNo
end
回复
psxfghost 2003-05-13
给你一个帮助里的例子:
IF (@ErrorSaveVariable <> 0)
BEGIN
PRINT 'Errors encountered, rolling back.'
PRINT 'Last error encountered: ' +
CAST(@ErrorSaveVariable AS VARCHAR(10))
ROLLBACK
END
ELSE
BEGIN
PRINT 'No Errors encountered, committing.'
COMMIT
END
RETURN @ErrorSaveVariable

^_^
回复
black_snail 2003-05-13
缺少END
回复
wandering_guy 2003-05-13
把then去掉试试
回复
joygxd 2003-05-13
CREATE PROCEDURE zzz(@courseNo char(15))
AS
if @courseNo is null
begin
select *
from course
end
else
begin
select *
from course
where course.courseNo=@courseNo
end
GO
回复
wgy2008 2003-05-13
CREATE PROCEDURE zzz(@courseNo char(15))
AS
if @courseNo is null
begin
select *
from course
end
else
begin
select *
from course
where course.courseNo=@courseNo
end
GO
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2003-05-13 02:05
社区公告
暂无公告