依米流沙 2021-09-29 12:29 采纳率: 80%
浏览 117
已结题

第三题和第四题 求解 加急

img

img

  • 写回答

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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 10月7日
  • 已采纳回答 9月29日
  • 创建了问题 9月29日

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler