求助:比较难的SQL语句

rex_chen2005 2007-05-15 09:22:58
(1)创建一自定义函数FIND,参数为学生的学号,返回值为该生姓名及性别
(2)创建一存储过程,其功能是用来查询学号为“20004071102”的学生是否存在,若存在,则显示其学号、姓名、性别、所选修的课程的课程名及成绩值,否则显示“查无此人”
...全文
218 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
TenRoon 2007-08-31
  • 打赏
  • 举报
回复
select是查询啊!这有什么不知道的!装比吧
rex_chen2005 2007-05-15
  • 打赏
  • 举报
回复
问一下,select 1是什么意思?学号:20004071102怎么输入 啊?
free_pop2k 2007-05-15
  • 打赏
  • 举报
回复
2)
利用上面的数据
create proc dbo.proc_test(@学号 varchar(10))
as
begin
set nocount on
if exists(select 1 from t where 学号=@学号)
select 姓名,性别 from t where 学号=@学号
else
print '查无此人'
end
free_pop2k 2007-05-15
  • 打赏
  • 举报
回复
1)创建一自定义函数FIND,参数为学生的学号,返回值为该生姓名及性别
为什么不建一个procedure呢?
create table t(学号 varchar(10),姓名 varchar(10),性别 varchar(2))
insert into t
select '001','张三','男'
union all
select '002','小花','女'

--select * from t

create proc dbo.proc_test(@学号 varchar(10))
as
begin
set nocount on
select 姓名,性别 from t where 学号=@学号
end

proc_test '001'

drop table t
drop proc proc_test
张云飞VIR 2007-05-15
  • 打赏
  • 举报
回复
楼上做的很详细了
lzhcxc 2007-05-15
  • 打赏
  • 举报
回复
(2)

create proc pc(@学号 nvarchar(20))
as
if exists(select 1 from 学生表 where 学号=@学号)
select * from 学生表 where 学号=@学号
else
select '查无此人'
lzhcxc 2007-05-15
  • 打赏
  • 举报
回复
(1)
create function FIND(@学号 nvarchar(20))
returns table
as
return(select 姓名,性别 from 学生表 where 学号=@学号)

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧