您现在的位置: 艺术无忧网 >> 教  程 >> 程序设计 >> 软件设计 >> 文章正文 用户登录 新用户注册
SQL语句和存储过程 查询语句的流程控制           
SQL语句和存储过程 查询语句的流程控制
作者:佚名 文章来源:不详 点击数: 更新时间:2006-1-5

drop table classname
declare @TeacherID int
declare @a char(50)
declare @b char(50)
declare @c char(50)
declare @d char(50)
declare @e char(50)
set @TeacherID=1

select @a=DRClass1, @b=DRClass2, @c=DRClass3, @d=DRClass4, @e=DRClass5 from Teacher Where TeacherID = @TeacherID

create table classname(classname char(50))
insert into classname (classname) values (@a)
if (@b is not null)
begin
insert into classname (classname) values (@b)

if (@c is not null)
begin
insert into classname (classname) values (@c)

if (@d is not null)
begin
insert into classname (classname) values (@d)
if (@e is not null)
begin
insert into classname (classname) values (@e)
end
end
end
end

select * from classname

以上这些SQL语句能不能转成一个存储过程?我自己试了下
ALTER PROCEDURE Pr_GetClass

@TeacherID int,
@a char(50),
@b char(50),
@c char(50),
@d char(50),
@e char(50)
as

select @a=DRClass1, @b=DRClass2, @c=DRClass3, @d=DRClass4, @e=DRClass5 from Teacher Where TeacherID = @TeacherID
DROP TABLE classname
create table classname(classname char(50))

insert into classname (classname) values (@a)
if (@b is not null)
begin
insert into classname (classname) values (@b)

if (@c is not null)
begin
insert into classname (classname) values (@c)

if (@d is not null)
begin
insert into classname (classname) values (@d)
if (@e is not null)
begin
insert into classname (classname) values (@e)
end
end
end
end

select * from classname
但是这样的话,这个存储过程就有6个变量,实际上应该只提供一个变量就可以了

主要的问题就是自己没搞清楚 @a,@b,@C,@d 等是临时变量,是放在as后面重新做一些申明的,而不是放在开头整个存储过程的变量定义。

本新闻共2页,当前在第1页  1  2  

文章录入:艺术无忧    责任编辑:艺术无忧 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    高级搜索
    我要了布文章>>
    专题导行>>
    最新热门>>
    最新推荐>>
    相关文章>>
  • 一张曝光照片的修复过程

  • 将美眉照片处理成CG效果

  • [ImageReady教程系列1]制

  • Vue 5 Esprit材质编辑器

  • MP3 播放器 线控制作教程

  • SQL Server 连接基础知识

  • 将SQL Server中所有表的

  • 如何灵活地运用SQL Inje

  • 蓝雨设计整站SQL注入漏洞

  • 怎样做sql server数据库

  • | 关于我们 | 广告服务 | 制作服务 | 经典案例 | 免责申明 | 联系站长 | 友情链接 | 版权申明
    艺术无忧网 版权所有 | 主办:浙江省设计艺术家协会 服务热线:0571-28868987
    浙ICP备05080493