开发者

validation for filing shift request (for workers) in sql

i'm new here and in dealing with sql server

i need to add a proc in sql that is checking if worker said he cant work over 4 shift in one week sql will print a messege..

i got something like this:

create proc proc_eror_worker_request

@开发者_如何学Gomax_ccwshift int output,
@bla int output

as

set @max_ccwshift=4
if exists(select*from dbo.Request  having  count(dbo.Request.Date_CantWork)>@max_ccwshift )
    begin 
        print 'wokers submited litle shifts'                
        set @bla=count(dbo.Request.Date_CantWork)
        select @bla
        from  dbo.Request

        return 1
    End
        Else
            begin
            print 'everything is OK!'
            return 0            
        End
Go

i'm new at this.. so please help me

thanks in advance..


I think you are close-ish to what you are after. Have you tried running this?

A MAJOR issue I see is that you don't have any selection for which worker you are looking at. I'm assuming there should be some filter like

WHERE Worker_ID = xxx

otherwise you are checking all the workers in the table and will get some strange results.

One other problem I see is here:

print 'wokers submited litle shifts'                
set @bla=count(dbo.Request.Date_CantWork)
select @bla
from  dbo.Request

I'm guessing that would return a syntax error. It should be:

print 'wokers submited litle shifts'                
select @bla=count(Date_CantWork)
from  dbo.Request

What do you get if you run it as you wrote it?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜