码迷,mamicode.com
首页 > 数据库 > 详细

在server sql中如何编写存储过程

时间:2017-02-13 15:06:30      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:server   apt   blog   sql   sid   toc   class   rom   view   

--这是创建一个叫做StudentsGrtByTuTorIDOrClassID的存储过程
CREATE PROCEDURE [dbo].[StudentsGetByTutorIDOrClassID] 
(@TeacherID varchar(10),@ClassID varchar(14))
AS
Begin

    if((@ClassID<>‘‘)and(@ClassID is not null))
    begin
        --根据班级编号查询学生名单信息 这里写你想写的sql语句
        Select StudentID,Name,Sex,ClassCode,SUBSTRING(ClassCode,1,14) as ClassID,ClassName,dbo.GetStudyFlagToCh(StudyFlag) as StudyFlagCaption  from StudentInfoView where ClassCode like @ClassID+% order by ClassCode
    end
    else begin
        ----根据辅导员编号查询学生名单信息
        Select StudentID,Name,Sex,ClassCode,SUBSTRING(ClassCode,1,14) as ClassID,ClassName,dbo.GetStudyFlagToCh(StudyFlag) as StudyFlagCaption  from StudentInfoView A,ClassTutorInfo B 
        where SUBSTRING(A.ClassCode,1,14)=B.ClassID and B.TeacherID = @TeacherID order by A.ClassCode

    end
end


--exec StudentsGetByTutorIDOrClassID 0413,‘‘
--exec StudentsGetByTutorIDOrClassID 0413,20150610020002

留作笔记

在server sql中如何编写存储过程

标签:server   apt   blog   sql   sid   toc   class   rom   view   

原文地址:http://www.cnblogs.com/Krloypower/p/6393715.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!