Monday, March 19, 2012

help with a querie

i need to finish to define this function

create function okJetsHelpFunc
(@.idevent INT)
Returns Table
AS
return select j.*
from jet as j
where j.eventid = @.idevent and abs(dbo.eta(j.id))>4.5 and dbo.pt(j.id)>20.0

GO

right now is working perfectly, but i need to put a condition that return all the jets information if they are 3 jets that fullfil the where statement, and return a null table if not
right now i have this, but it doesnt work

create function okJetsHelpFunc
(@.idevent INT)
Returns Table
AS
if (select count(j.id)
from jet as j
where j.eventid = @.idevent and abs(dbo.eta(j.id))>4.5 and dbo.pt(j.id)>20.0)>=3
return select j.*
from jet as j
where j.eventid = @.idevent and abs(dbo.eta(j.id))>4.5 and dbo.pt(j.id)>20.0

Return null

GO
|||

See if this works:

create function okJetsHelpFunc
(@.idevent INT)
Returns Table
as
return
( select j.*
from jet as j
where j.eventid = @.idevent
and abs(dbo.eta(j.id))>4.5
and dbo.pt(j.id) > 20.0
and ( select count(j.id)
from jet as j
where j.eventid = @.idevent
and abs(dbo.eta(j.id)) > 4.5
and dbo.pt(j.id) > 20.0
) >= 3
)

GO

No comments:

Post a Comment