Try It Out! Mix Them Up! Input & Output!

本文介绍了一个SQL存储过程,用于从数据库中随机选择符合特定性别条件的学生记录。该过程接受性别作为输入参数,并返回一个学生编号。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

--Try to make a script  

 

--To get full info  

 

--For a random Female (or Male) student.

 

--tfu@isb.bj.edu.cn

 

if object_id('outputtest') is not null   

drop proc outputtest   

go   

create proc outputtest   

@input_Gender Varchar(10),   

@Output_Student_number int output 

As   

declare @FunctionVariable varchar(50)   

set @FunctionVariable='9'   

select Top 1 @Output_student_number=student_number  

from students    

where  

grade_level=@FunctionVariable 

and 

Gender=@input_Gender 

order by newid()   

select @Output_student_number as IN_PROC_STDNUM   

  

------------------------------------------------------------------------------ 

 

declare @input_new_Gender varchar(10) 

declare @output_new_Student_number int 

Set @input_new_Gender='F' 

exec outputtest    

@input_new_Gender,   

@output_new_Student_number output 

select    

@Output_new_Student_number as OUTPUT_STUDNUM  

select * from students s   

where s.Gender=@input_new_Gender 

and s.student_number=@output_new_Student_number 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值