自用自用存储过程

创建

create procedure getPractice
	
	@name varchar(24)
as
	
	if (select count(*) from D_Info where D_Name=@name) <> 0 
		begin
			select st_info.St_ID,st_info.St_Name,s_c_info.c_no,C_Info.C_Name
			from st_info,s_c_info,C_Info
			where left(st_info.St_ID,2) = (select D_ID
										   from D_Info
										   where D_Name=@name)
			and s_c_info.st_id=st_info.St_ID 
			and s_c_info.c_no=C_Info.C_No
			and C_Info.C_Type='实践'
		end
	else
		print('院系不存在')
go

调试

exec getPractice '法学院'
exec getPractice '材料科学与工程学院'

改名

sp_rename 'getPractice','getPctStu'

修改

alter procedure getPctStu
	
	@name varchar(24) 
as
	
	if (select count(*) from D_Info where D_Name=@name) <> 0 
		begin
			select count(*) 
			from st_info,s_c_info,C_Info
			where left(st_info.St_ID,2) = (select D_ID
										   from D_Info
										   where D_Name=@name)
			and s_c_info.st_id=st_info.St_ID 
			and s_c_info.c_no=C_Info.C_No
			and C_Info.C_Type='实践'
		end
	else
		print('院系不存在')
go

调试2

exec getPctStu '法学院'

exec getPctStu '法学院啊'

再改

alter procedure getPctStu
	
	@name varchar(24) -- mysql中表示24表示24个字符 sqlserver也不是utf-8
as
	
	if (select count(*) from D_Info where D_Name=@name) <> 0 
		begin
			-- distinct st_info.St_ID 
			select count(distinct st_info.St_ID)
			from st_info,s_c_info,C_Info
			where left(st_info.St_ID,2) = (select D_ID
										   from D_Info
										   where D_Name=@name)
			and s_c_info.st_id=st_info.St_ID 
			and s_c_info.c_no=C_Info.C_No
			and C_Info.C_Type='实践'
		end
	else
		print('院系不存在')
go

调试3

exec getPctStu '法学院'

exec getPctStu '法学院啊'

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值