首页 > 代码库 > 在server sql中如何编写存储过程

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

--这是创建一个叫做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中如何编写存储过程