2条回答 默认 最新
- 神仙别闹 2021-09-29 13:07关注
这是第三题的大概解题思路,中文名称全部换成实际的表名和列明即可。
create procedure 存储过程名称 @Number nvarchar(50) --员工编号 as begin declare @CountNumber as varchar(10),@name as varchar(50), @time as datetime,@message as varchar(100) select @CountNumber=COUNT(*) from 员工表 where 员工编号=@Number and 部门<>10 and 入职时间 > (select top 1 入职时间 from 员工表 where 部门=10 order by 入职时间 desc) if @CountNumber>0--输出员工、入职时间 begin select @name=员工姓名,@time=入职时间 from 员工表 where 员工编号=@Number print '员工姓名:'+@name+' 入职时间:'+@time end else--员工保存在 begin set @message= '员工编号不存在' print '结果:'+@message end end
这是第四题的思路
--第一种循环:利用游标循环 declare @id int,@value nvarchar(100); begin declare c_test_main cursor fast_forward for select 员工姓名,工资 from emp;--查出需要的集合放到游标中 open c_test_main;--打开游标 while 1=1 --开始循环 begin fetch next from c_test_main into @id,@value; --赋值到变量中 if(@@fetch_status!=0)break;--如果没有结果退出循环 if @value<1200 begin print '员工:'+@id+'该加工资了' end else if @value>=1200 and @value<2100 begin print '员工:'+@id+'还行' end else begin print '员工:'+@id+'有钱人' end end close c_test_main --关闭游标 deallocate c_test_main --释放游标 end go --第二种循环:特定ID循环,类似For循环 declare @max int declare @i int select ROW_NUMBER() over (order by id) as 'Id',员工姓名,工资 into #temp from emp select @max=max(Id) from #temp set @i = 1 while (@i <= @max) begin begin declare @name int declare @money int select @name=员工姓名,@money=工资 from #temp where ID = @i if @money<1200 begin print '员工:'+@name+'该加工资了' break end else if @money>=1200 and @money<2100 begin print '员工:'+@name+'还行' break end else begin print '员工:'+@name+'有钱人' break end end set @i = @i + 1 end go
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥20 java在应用程序里获取不到扬声器设备
- ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
- ¥15 Attention is all you need 的代码运行
- ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
- ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
- ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
- ¥80 部署运行web自动化项目
- ¥15 腾讯云如何建立同一个项目中物模型之间的联系
- ¥30 VMware 云桌面水印如何添加
- ¥15 用ns3仿真出5G核心网网元