use MyGZGL
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[kq_present]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[kq_present]
GOcreate procedure dbo.kq_presentas
begin
Declare @工号 Nvarchar(50) ---工号
Declare @事假时数 decimal(6,2) --事假时数
Declare @病假时数 decimal(6,2) --病假时数
Declare @旷工时数 decimal(9,2) --旷工时数
Declare @迟到 decimal(9,2)
declare @上班天数 decimal(9,2)
declare @全勤奖 decimal(9,2)
declare @工资年月 datetime
declare @本月正常天数 int
set @工资年月 =(select value from ParameterTable where name='工资年月')
set @本月正常天数 =(select dbo.standard_Workday ( @工资年月 )) declare cur cursor for SELECT [工号],事假时数,病假时数,旷工时数,迟到,上班天数,全勤奖 FROM [kagagzgl].[dbo].[Salary]
open cur
fetch next from cur into @工号,@事假时数,@病假时数,@旷工时数,@迟到,@上班天数,@全勤奖while( @@fetch_status=0)
begin
if(@事假时数 > 0)
set @全勤奖 = 0
if(0<@病假时数<16)
set @全勤奖 = 0
if( @旷工时数 > 0)
set @全勤奖 = 0
if( @迟到 > 0)
set @全勤奖 = 0 if( @上班天数 < @本月正常天数)
set @全勤奖 = 0
else
set @全勤奖 = 50
update Salary set 全勤奖=@全勤奖 where CURRENT OF cur
endend
goif语句是如何写的? 用case 语句如何写的.还是就用if语句就可以了
主要是以下的写法.
while( @@fetch_status=0)
begin
if(@事假时数 > 0)
set @全勤奖 = 0
if(0<@病假时数<16)
set @全勤奖 = 0
if( @旷工时数 > 0)
set @全勤奖 = 0
if( @迟到 > 0)
set @全勤奖 = 0 if( @上班天数 < @本月正常天数)
set @全勤奖 = 0
else
set @全勤奖 = 50
update Salary set 全勤奖=@全勤奖 where CURRENT OF cur
end
希望高人给更正,
另外这句 if(0<@病假时数<16) 针对这种在什么数字之前的又是如何写.?
谢谢
...
declare @i int
set @i = 1
if @i >0 and @i <2
print '11'
else
print '22'
输出为11
用if比较清晰而且易于维护。
我想学习一下.
改为上面说的.
直接update +case when 就行了
DROP PROCEDURE [dbo].[kq_present]
GO
create procedure dbo.kq_present
as
begin
Declare @工号 Nvarchar(50) ---工号
Declare @事假时数 decimal(6,2) --事假时数
Declare @病假时数 decimal(6,2) --病假时数
Declare @旷工时数 decimal(9,2) --旷工时数
Declare @迟到 decimal(9,2)
declare @上班天数 decimal(9,2)
declare @全勤奖 decimal(9,2)
declare @工资年月 datetime
declare @本月正常天数 int
set @工资年月 =(select value from ParameterTable where name='工资年月')
set @本月正常天数 =(select dbo.standard_Workday ( @工资年月 ))
update Salary
set 全勤奖=
case
when 事假时数>0
or 病假时数>0 and 病假时数<16
or 旷工时数>0
or 迟到>0
or 上班天数<@本月正常天数
then 0
else 50
endend
SET 全勤奖=CASE WHEN 事假时数>0 THEN 0
WHEN 病假时数>0 AND 病假时数<16 THEN 0
WHEN 旷工时数>0 THEN 0
WHEN 迟到>0 THEN 0
WHEN 上班天数<dbo.standard_Workday ( @工资年月 ) THEN 0
ELSE 50
END-------------------------------------------------------------------------这样应该就可以了,不过我不敢保证。
等明天到公司测试一下再说吧